To check the list of all possible ggplot libraries look [here]{https://exts.ggplot2.tidyverse.org/gallery/}
- ggsci - To get Scientific Journal specific colour schemes
- ggfortify - To make PCA plots
- ggpubr, ggstatsplot - To attach stats to plots, and also to arrange multiple plots together
- patchwork - Quickly combine plots together
- corrplot, pheatmap - To make correlation plots, hierarchical clustering heatmaps
- GGally - To make ggpairs plots
- ggtranscript
- ggrepel - to repel annoying plot labels
- ggalluvial - To make sankey diagrams
- ggupset, ComplexUpset - To make upset plots
Template from ggplot2 cheatsheet
ggplot(data = <DATA>) +
<GEOM_FUNCTION>(mapping = aes( <MAPPINGS>),
stat = <STAT>,
position = <POSITION>) +
<COORDINATE_FUNCTION> +
<FACET_FUNCTION> +
<SCALE_FUNCTION> +
<THEME_FUNCTION>
geom_point(data = df1, aes(x = a, y = b))
geom_hist(data = df1, aes(x = a))
labs(title = "This is the ggplot2 lookup guide!", subtitle = "GitHub", caption = "Source: ggplot2",
tag = "A", x = "Command", y = "Function")
geom_area(df1)
geom_vline(xintercept = 0.5, linetype = "dotted")
geom_line(df1)
- limits is the scale limit to be plotted/shown on graph
- breaks is the numbers to be displayed in the axis
- scales::comma displays 1000 as 1,000 and 10000 as 10,000, scales::percent displays 95 as 95%
- expand is the padding beyoond the limit, for e.g. right padding is 10000 + (10000 - 1)*1 + 2, left padding is 0 + (0-1)*1 -2
scale_x_continuous(limits = c(0,10000), breaks = c(0, 100, 1000, 10000), labels = scales::comma, expand = (1, 2)) +
scale_y_continuous(limits = c(0, 100), labels = scales::percent)
theme_set(theme_minimal(), legnend.position = "bottom", legend.title = "Tutorial")
Divide the data into multiple datasets based on the factor of any given column
facet_wrap(~ DxCondition, ncol = 1)
Combining multiple different plots
library(patchwork)
plot1 + plot2 + plot3 + plot4