Debian Codegraph @

vignettes/Quick_Introduction.Rmd

raw
1 ---
2 title: "Quick Introduction"
3 date: "`r Sys.Date()`"
4 author: "Tal Galili"
5 output:
6 html_vignette:
7 toc: yes
8 editor_options:
9 chunk_output_type: console
10 ---
11 <!--
12 %\VignetteEngine{knitr::rmarkdown}
13 %\VignetteIndexEntry{A quick introduction to dendextend (start here)}
14 -->
15
16
17 ```{r, echo = FALSE, message = FALSE, warning=FALSE}
18 library(dendextend)
19 library(knitr)
20 knitr::opts_chunk$set(
21 cache = TRUE,
22 dpi = 75,
23 fig.width = 6, fig.height = 6,
24 # comment = "#>",
25 tidy = FALSE)
26
27 # https://stackoverflow.com/questions/24091735/why-pandoc-does-not-retrieve-the-image-file
28 # < ! -- rmarkdown v1 -->
29
30 ```
31
32
33
34 Start
35 ------------------------------
36
37 Load:
38
39 ```{r}
40 library(dendextend) #
41 ```
42
43
44 Create a dendrogram (if you don't know what `%>%` is, read about it [here](https://CRAN.R-project.org/package=magrittr/vignettes/magrittr.html) ) :
45
46 ```{r}
47 dend <- c(1:5) %>% dist %>% hclust("ave") %>% as.dendrogram
48 ```
49
50 Plot:
51
52 ```{r}
53 plot(dend)
54 ```
55
56 Get/set labels
57
58 ```{r}
59 labels(dend)
60 labels(dend) <- c("A", "B", "extend", "dend", "C")
61 labels(dend)
62 ```
63
64 Get/set labels' colors
65
66 ```{r}
67 labels_colors(dend)
68 labels_colors(dend) <- rainbow(5)
69 labels_colors(dend)
70 plot(dend)
71 ```
72
73
74 Cut-tree, and color branches
75
76 ```{r}
77 cutree(dend, k = 2)
78 dend <- color_branches(dend, k = 2)
79 plot(dend)
80 ```
81
82
83 Sort
84
85 ```{r}
86 dend2 <- sort(dend)
87 plot(dend2)
88 ```
89
90 Compare
91
92 ```{r}
93 tanglegram( dend, dend2 )
94 ```
95
96 Cor
97
98 ```{r}
99 cor_cophenetic( dend, dend2 )
100 ```
101
102
103 ggplot2
104
105 ```{r}
106 library(ggplot2)
107 ggplot(dend)
108 ```
109
110 Send to plot.ly
111
112 ```{r}
113
114 # library(plotly)
115 # set_credentials_file(...)
116 # you'll need to get it from here: https://plot.ly/ggplot2/getting-started/
117
118 # ggplot(dend)
119 # py <- plotly()
120 # py$ggplotly()
121
122 ```
123
124
125
126
127
128
129
130