boxlpotwithline
写在前面
【这图怎么画】系列的图都来自VIP群
里同学的提问。推文只是对图片的复现,不代表作者对图片展现形式的认同。欢迎同学们在群里分析有意思的图片。
本期图片
❝「Title:」A distinct clade of Bifidobacterium longum in the gut of Bangladeshi children thrives during weaning
「Journal:」Cell
「DOI」:10.1016/j.cell.2022.10.011
❞❝Box shows interquartile range, whiskers show data range, and the horizontal line in the box shows the median. Dashed lines show longitudinal trends connecting medians across time points.
箱线图,虚线为中位数连线。
❞
复线结果
示例数据和代码领取
木舟笔记永久VIP企划
「权益:」
- 「木舟笔记所有推文示例数据及代码(「在VIP群里」实时更新」)。
data+code
绘图
# data prepare data <- data.frame(runif(30,0,1), runif(30,0.8,1), runif(30,0.8,1), runif(30,0.25,0.85), runif(30,0,0.7), runif(30,0,0.5), runif(30,0,0.1)) row.names(data)<- paste0('sample',1:30) colnames(data) <- paste0('time',1:7) data$sample = row.names(data) head(data) # wide to long library(tidyr) dt_plot <- gather(data, time, value,-sample) head(dt_plot) # calculate grouped medians median = data.frame(time = paste0('time',1:7) , median = tapply(dt_plot$value, dt_plot$time, median) ) head(median) ## plot library(ggplot2) library(ggbeeswarm) ggplot(dt_plot,aes(time,value))+ geom_boxplot()+ geom_beeswarm(shape = 21,color = '#9ca7ce',fill = '#9ca7ce', size = 3.5,cex = 1.5, stroke = 0.6,alpha = 0.8)+ geom_line(data = median, mapping = aes(x = time, y = median, group=1), color="black",linetype = 'longdash',size = 2)+ theme_bw()+ labs(x = "", y = "")+ ggtitle("My Plot Title")+ theme(axis.text.x = element_text(color="black",size=14), axis.text.y=element_text(color="black",size=14), plot.title = element_text(size = 14, face = "bold", color = "black"), panel.border = element_rect(fill=NA,color="black", size=1, linetype="solid")) ggsave('boxlpotwithline.pdf',width = 5,height = 5)
boxplot+line
往期内容
- 资源汇总 | 2022 木舟笔记原创推文合集(附数据及代码领取方式)
- CNS图表复现|生信分析|R绘图 资源分享&讨论群!
- R绘图 | 浅谈散点图及其变体的作图逻辑
- 这图怎么画| 有点复杂的散点图
- 这图怎么画 | 相关分析棒棒糖图
- 组学生信| Front Immunol |基于血清蛋白质组早期诊断标志筛选的简单套路
- (免费教程+代码领取)|跟着Cell学作图系列合集
- Q&A | 如何在论文中画出漂亮的插图?
- 跟着 Cell 学作图 | 桑葚图(ggalluvial)
- R实战 | Lasso回归模型建立及变量筛选
- 跟着 NC 学作图 | 互作网络图进阶(蛋白+富集通路)(Cytoscape)
- R实战 | 给聚类加个圈圈(ggunchull)
- R实战 | NGS数据时间序列分析(maSigPro)
- 跟着 Cell 学作图 | 韦恩图(ggVennDiagram)