其他
ggplot 绘制箱线图
1引言
ggplot 绘制一个箱线图看看。
2画图
加载内置数据:
library(ggplot2)
library(ggpubr)
library(tidyverse)
data("mtcars")
# 星号显示
symnum.args <- list(cutpoints = c(0, 0.0001, 0.001, 0.01, 0.05, 1),
symbols = c("****", "***", "**", "*", "ns"))
画图:
# plot
ggplot(mtcars,aes(x = factor(cyl),y = mpg)) +
# errorbar
stat_boxplot(aes(color = factor(cyl)),
geom ='errorbar',width = 0.2,size = 0.8,) +
# boxplot
geom_boxplot(aes(color = factor(cyl)),
width = 0.5,
notch = T,
notchwidth = 0.5,
outlier.color = 'white',
size = 0.8) +
# line
geom_line(data = media_val,
aes(x = factor(cyl),y = mval,group = 1),
size = 1) +
# jitter
geom_jitter(aes(color = factor(cyl)),
size = 3,alpha = 0.5,
position = position_jitter(width = 0.2)) +
theme_classic(base_size = 18) +
# 主题调整
theme(aspect.ratio = 1.5,
axis.text.x = element_text(angle = 45,hjust = 1,color = 'black',size = 16),
legend.position = 'none') +
# 颜色
scale_color_brewer(palette = 'Set1') +
# x轴标签
scale_x_discrete(label = c('group1','group2','group3')) +
xlab('') +
# 差异检验
stat_compare_means(comparisons = list(c('4','6'),c('4','8'),c('8','6')),
label.y = 38,size = 5,
step.increase = 0.13,
symnum.args =symnum.args)
欢迎加入生信交流群。加我微信我也拉你进 微信群聊 老俊俊生信交流群
哦,数据代码已上传至QQ群,欢迎加入下载。
群二维码:
老俊俊微信:
知识星球:
所以今天你学习了吗?
今天的分享就到这里了,敬请期待下一篇!
最后欢迎大家分享转发,您的点赞是对我的鼓励和肯定!
如果觉得对您帮助很大,赏杯快乐水喝喝吧!
往期回顾
◀m6A metagene distribution 计算详解
◀跟着 nature cell biology 学绘图-小提琴图
◀...