Last active
September 16, 2022 16:51
-
-
Save sahilseth/37a567810a8bdcb64bc3b96b33340b42 to your computer and use it in GitHub Desktop.
ggplot examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override legend | |
# get it inside the plot, and remove alpha | |
theme(legend.position = c(0, 0.2), | |
legend.background = element_blank()) + | |
guides(colour = guide_legend(override.aes = list(alpha = 1))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1 | |
# https://github.com/kassambara/ggpubr | |
my_comparisons <- list( c("gb", "gc"), c("gb", "noref")) | |
ggplot(df_cnts_per_samp, aes(ref_type, n, color = ref_type)) + | |
geom_jitter() + | |
geom_violin(alpha = 0) + | |
theme_cowplot() + | |
scale_y_log10() + | |
scale_color_npg(name = "") + | |
xlab("Reference type") + | |
ylab("Number of mutations") + | |
stat_compare_means(comparisons = my_comparisons) + # Add pairwise comparisons p-value | |
stat_compare_means(label.y = 1, label.x = "gc") # Add global p-value | |
# to have different groups, follow this: | |
# https://www.datanovia.com/en/lessons/ggplot-stripchart/ | |
ggplot(x.subset, aes(x = lbl, y = value, color = gene_id)) + | |
stat_summary(aes(color = gene_id), fun.data = "mean_sdl", geom="pointrange", shape=18, size=0.8, position = position_dodge(0.8)) + | |
geom_jitter(aes(x = lbl, y = value, color = gene_id), alpha = 0.5, | |
size = 1.2, position = position_jitterdodge(jitter.width = 0.2, dodge.width = 0.8)) + | |
# geom_violin(alpha = 0) + | |
scale_color_manual(values = gene_colors, name = NULL) + | |
theme_cowplot() + |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://github.com/kassambara/ggpubr | |
my_comparisons <- list( c("gb", "gc"), c("gb", "noref")) | |
p2 = ggplot(df_cnts_per_samp, aes(ref_type, n, color = ref_type)) + | |
geom_jitter() + | |
geom_violin(alpha = 0) + | |
theme_cowplot() + | |
scale_y_log10( | |
breaks = scales::trans_breaks("log10", function(x) 10^x), | |
labels = scales::trans_format("log10", scales::math_format(10^.x))) + | |
# annotation_logticks() + | |
scale_color_npg(name = "") + | |
xlab("Reference type") + | |
ylab("Number of mutations") + | |
stat_compare_means(comparisons = my_comparisons) + # Add pairwise comparisons p-value | |
stat_compare_means(label.y = 1, label.x = "gc") # Add global p-value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
computerworld snippets: