Evolutionary origins of the SARS-CoV-2 sarbecovirus lineage responsible for the COVID-19 pandemic
image.png
本地文件 s41564-020-0771-4.pdf
https://github.com/plemey/SARSCoV2origins
今天的推文我们来重复一下论文中的 Figure 2 中的簇状柱形图
image.png
之前的推文也介绍过R语言ggplot2做簇状柱形图的代码,这个图和之前的比较常规的簇状柱形图的区别在于多了一个贴近坐标轴的分组线段,今天的推文主要介绍的是这个的实现办法
有一个R包是ggh4x,这里有函数可以直接控制坐标轴的范围
image.png
library(readxl)
library(ggplot2)
library(ggh4x)
df<-read_excel("Figure2.xlsx")
df
ggplot(data=df,aes(x=x,y=y))+
geom_col(aes(fill=group),
position = position_dodge(0.4),
width = 0.3)
image.png
df$x<-factor(df$x,
levels = c("NTD","CTD","Variable loop","S1 3 end","S2"))
df$group<-factor(df$group,
levels = c("Pangolin Guangdong 2019",
"Pangolin Guangxi 2017 (P5L)",
"Yunnan 2013 (RaTG13)"))
ggplot(data=df,aes(x=x,y=y))+
geom_col(aes(fill=group),
position = position_dodge(0.4),
width = 0.3,
show.legend = F)+
scale_y_continuous(expand = c(0,0),
limits = c(-0.1,1))+
theme_minimal()+
theme(panel.grid = element_blank(),
axis.line.y = element_line(),
axis.ticks.y = element_line())+
labs(x="loop removed",
y="Genetic distance from human\nSARS-CoV-2\n(substitutions per site)")+
annotate(geom = "segment",
x=0.6,y=0,xend = 5.4,yend = 0)+
scale_fill_manual(values = c("#ff7a17",
"#808284",
"#1db280"))+
# theme(#plot.margin = unit(c(0.5,0.1,2,0.5),"cm"),
#
# axis.text.x = element_text(margin =
# margin(2,0,0,0,unit = "cm")))+
guides(y=guide_axis_truncated(trunc_lower = 0,
trunc_upper = 1)) -> p1
p1
image.png
p1+ annotate(geom = "segment",
x=0.6,xend=1.4,
y=-0.05,yend = -0.05,
size=5,
color="#c2abd3")+
annotate(geom = "segment",
x=1.6,xend=2.4,
y=-0.05,yend = -0.05,
size=5,
color="#d899be")+
annotate(geom = "segment",
x=2.6,xend=3.4,
y=-0.05,yend = -0.05,
size=5,
color="#d5d6e9")+
annotate(geom = "segment",
x=3.6,xend=4.4,
y=-0.05,yend = -0.05,
size=5,
color="#d899be")+
annotate(geom = "segment",
x=4.6,xend=5.4,
y=-0.05,yend = -0.05,
size=5,
color="#f8a5c9")
我的B站同名账号 小明的数据分析笔记本 会更新一些关于R语言和python数据分析和数据可视化作图的入门内容 还有生物信息学入门的相关内容 的视频。仔细想了想,还是以问题为导向录制视频效果可能会好一些。所以建了一个群来收集大家的问题,大家有相关问题可以在群里提出,尽可能的详细描述。如果我恰好会的话我会抽时间录制视频介绍解决办法。加群需要实名制(学校专业昵称)。当然大部分问题我大概率是不会。感兴趣的可以扫描上面二维码加群。群里的成员需要担任一周的志愿者,每天收集一下群里提出的问题和解决办法。如果不愿意在这个上面浪费时间,请不要加群。如果不能加群的话可以添加我的微信
mingyan24
我来拉你入群
欢迎大家关注我的公众号
小明的数据分析笔记本
小明的数据分析笔记本 公众号 主要分享:1、R语言和python做数据分析和数据可视化的简单小例子;2、园艺植物相关转录组学、基因组学、群体遗传学文献阅读笔记;3、生物信息学入门学习资料及自己的学习笔记!