Debian Codegraph @

inst/doc/modify_output.Rmd

raw
1 ---
2 title: "Modifying ggdendogram output"
3 output: rmarkdown::html_vignette
4 vignette: >
5 %\VignetteIndexEntry{Modifying ggdendogram output}
6 %\VignetteEngine{knitr::rmarkdown}
7 %\VignetteEncoding{UTF-8}
8 ---
9
10 ```{r, include = FALSE}
11 knitr::opts_chunk$set(
12 collapse = TRUE,
13 comment = "#>"
14 )
15 ```
16
17
18 If you use `ggdendrogram()` to create your plot, the resulting object is a `ggplot`. You have full control over this using any function available in `ggplot`.
19
20 First create an example dataset.
21
22 ```{r setup}
23 library(ggdendro)
24 library(ggplot2)
25 hc <- hclust(dist(USArrests), "ave")
26 ```
27
28
29 Plot the default `ggdendrogram()` output:
30
31
32 ```{r example-default}
33 ggdendrogram(hc, rotate = FALSE, size = 2)
34 ```
35
36 Use a different theme:
37
38
39 ```{r example-1}
40 ggdendrogram(hc, rotate = FALSE, size = 2) +
41 theme_bw()
42 ```
43
44 Or modify just one element, for example add a y-axis.
45
46
47 ```{r example-2}
48 ggdendrogram(hc, rotate = FALSE, size = 2) +
49 theme( axis.line.y = element_line() )
50 ```
51
52 In summary, `ggdendrogram()` is a convenience function that creates a `ggplot`. Once you have this plot, you can modify the plot using tools that you are familiar with.