/
modify_output.Rmd
52 lines (36 loc) · 1.11 KB
/
modify_output.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
---
title: "Modifying ggdendogram output"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Modifying ggdendogram output}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
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`.
First create an example dataset.
```{r setup}
library(ggdendro)
library(ggplot2)
hc <- hclust(dist(USArrests), "ave")
```
Plot the default `ggdendrogram()` output:
```{r example-default}
ggdendrogram(hc, rotate = FALSE, size = 2)
```
Use a different theme:
```{r example-1}
ggdendrogram(hc, rotate = FALSE, size = 2) +
theme_bw()
```
Or modify just one element, for example add a y-axis.
```{r example-2}
ggdendrogram(hc, rotate = FALSE, size = 2) +
theme( axis.line.y = element_line() )
```
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.