Skip to content

Commit 65657fd

Browse files
committed
added tutorial for lollipop plot.
1 parent ae0c5c8 commit 65657fd

File tree

3 files changed

+43
-14
lines changed

3 files changed

+43
-14
lines changed

docs/several_plots.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ First of all, open a new R working script, and load our [example data](../exampl
4848

4949
```{r}
5050
>library("ComplexHeatmap")
51-
>upset_matrix <- data.frame(read.csv("/Users/kunhuang/repos/KunDH-2023-CRM-MSM_metagenomics/example_data/UpSet_matrix1.tsv",
51+
>upset_matrix <- data.frame(read.csv("path_to_the_package/KunDH-2023-CRM-MSM_metagenomics/example_data/UpSet_matrix1.tsv",
5252
header = TRUE,
5353
sep = "\t"))
5454
>rownames(upset_matrix) <- upset_matrix[, colnames(upset_matrix)[[1]]]
@@ -102,3 +102,42 @@ Similar codes can be used for another set of LefSe biomarkers associated with: R
102102
We can generate a nice plot showing the mutual biomarkers shared between different sexual practices by combining these plots.
103103
![UpSet plot](../images/upset_plot.jpg)
104104

105+
### Lollipop plot
106+
107+
#### R packages required
108+
109+
* [ggpubr](https://rpkgs.datanovia.com/ggpubr/)
110+
111+
In the last section, we will use lillipop plot to show the number of shared biomarkers associated with different sexual practices.
112+
Here, you can start directly from our prepared file [shared_biomarkers.tsv](../example_data/shared_biomarkers.tsv) containing the number of LefSe biomarkers shared by different sexual practices (categorized as *risk.increasing* and *risk.reducing*).
113+
114+
Firstly, open a new R working script, and load [shared_biomarkers.tsv](../example_data/shared_biomarkers.tsv) from `path_to_the_package/KunDH-2023-CRM-MSM_metagenomics/examples/`.
115+
116+
```{r}
117+
>library(ggpubr)
118+
>shared_biomarkers <- data.frame(read.csv("path_to_the_package/KunDH-2023-CRM-MSM_metagenomics/example_data/shared_biomarkers.tsv",
119+
header = TRUE,
120+
sep = "\t"))
121+
```
122+
123+
Once the data was loaded, we use a function [ggdotchart](https://rpkgs.datanovia.com/ggpubr/reference/ggdotchart.html) implement in [ggpubr](https://rpkgs.datanovia.com/ggpubr/) for visualization.
124+
125+
```{r}
126+
>ggdotchart(shared_biomarkers, x = "group.number", y ="shared.biomarker.number",
127+
color = "type", palette = c("#fb5238", "#469537"), size = 5,
128+
add = "segment",
129+
shape = 19,
130+
group = "cate",
131+
add.params = list(color = "lightgray", size = 2.5),
132+
position = position_dodge(0.25),
133+
ggtheme = theme_pubclean()
134+
) + geom_text(
135+
aes(label = n_common_sps, group = cate),
136+
position = position_dodge(0.8),
137+
vjust = -0.5, size = 3.5
138+
)
139+
```
140+
141+
![shared biomarker in combinations](../images/shared_biomarkers.jpg)
142+
143+
Note: The figures displayed above had been edited and arranged using inkscape on the base of the crude output in order to enhance the readability and aesthetic sense.

images/shared_biomarkers.jpg

92.4 KB
Loading

scripts/functions/several_plots.R

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
1-
#"""
2-
#1. The input should be a matrix compatible with UpSet plot.
3-
#2. mode should be optional, more than just intersect.
4-
#3. combination_column, background_column, and backgroud_patch_column should be given.
5-
#4. set_order can be adjusted by a vector of names.
6-
#5. ylim, and height also should be adjustable.
7-
#6. annotation_name_side, rotation angle.
8-
#7. parameters for decoration also should be adjustable.
9-
#"""
10-
11-
12-
13-
141

152
library("ComplexHeatmap")
163
upset_matrix <- data.frame(read.csv("/Users/kunhuang/repos/KunDH-2023-CRM-MSM_metagenomics/example_data/UpSet_matrix1.tsv",
@@ -47,3 +34,6 @@ decorate_annotation("# shared taxonomic biomarkers", {
4734
default.units = "native", just = c("left", "bottom"),
4835
gp = gpar(fontsize = 6, col = "#404040"), rot = 45)
4936
})
37+
38+
39+
View(upset_matrix)

0 commit comments

Comments
 (0)