今天的推文是回答B(yǎng)站關(guān)注者的一個(gè)問題
他的問題是
image.png
我找到論文來看了一下
image.png
圖片是
image.png
今天的推文我們試著來復(fù)現(xiàn)一下這個(gè)圖
首先是準(zhǔn)備數(shù)據(jù)
沒有找到論文提供的原始數(shù)據(jù)鳞尔,只能手動(dòng)將其整理到表格里了而叼。
image.png
這里用qq里面的截圖工具識(shí)別圖片文字還挺方便的
image.png
完整代碼
library(readxl)
library(ggplot2)
df<-read_excel("abcd.xlsx")
df
df$y<-factor(df$y,
levels = rev(unique(df$y)))
df$group<-factor(df$group,
levels = rev(unique(df$group)))
ggplot(data=df,aes(x=x,y=y,fill=group))+
geom_bar(stat = "identity",
position = position_dodge(0.9),
width = 0.8)+
scale_fill_manual(values = c("#4472c4","#ed7d31"))+
geom_text(aes(x+0.2,y,label=x),size=3,
position = position_dodge(0.9))+
theme_void()+
theme(legend.position = "bottom",
legend.justification = c(0.5,0),
legend.title = element_blank(),
legend.key.size = unit(2,'mm'),
legend.text = element_text(size=10),
plot.margin = unit(c(1,1,2,1),'mm'))+
geom_text(aes(x=-0.1,y=y,label=y),hjust=1)+
xlim(-11,5)+
geom_vline(xintercept = 0,color="grey")+
annotate(geom = "segment",
x=0,xend=-11,y=0.4,yend=0.4,
color="grey")+
annotate(geom = "segment",
x=0,xend=-11,y=2.5,yend=2.5,
color="grey")+
annotate(geom = "segment",
x=0,xend=-11,y=5.5,yend=5.5,
color="grey")+
annotate(geom = "segment",
x=0,xend=-11,y=12.5,yend=12.5,
color="grey")+
annotate(geom = "segment",
x=0,xend=-11,y=16.5,yend=16.5,
color="grey")+
annotate(geom = "text",
x=-11,y=1.5,label="Others",angle=90)+
annotate(geom = "text",
x=-11,y=4,label="Provisioning",angle=90)+
annotate(geom = "text",
x=-11,y=9,label="Cultural",angle=90)+
annotate(geom = "text",
x=-11,y=14.5,label="Regulationg",angle=90) -> p
pdf(file = "outp.pdf",
width = 14,height = 6,
family = "serif")
print(p)
dev.off()
image.png
整體的思路就是Y軸的坐標(biāo)軸標(biāo)簽去掉昭灵,用geom_text()
函數(shù)添加文本注釋的辦法作為標(biāo)簽栖茉,這樣有了坐標(biāo)位置添加橫線表示分組就很方便了
如果需要示例數(shù)據(jù)和代碼的話需要給文章打賞1元,悄悄話備注數(shù)據(jù)代碼
冗锁,如果你打賞了沒有收到我的回復(fù)數(shù)據(jù)代碼下載鏈接庞萍,可以給文章留言催我
歡迎大家關(guān)注我的公眾號
小明的數(shù)據(jù)分析筆記本
小明的數(shù)據(jù)分析筆記本 公眾號 主要分享:1、R語言和python做數(shù)據(jù)分析和數(shù)據(jù)可視化的簡單小例子;2莉擒、園藝植物相關(guān)轉(zhuǎn)錄組學(xué)酿炸、基因組學(xué)、群體遺傳學(xué)文獻(xiàn)閱讀筆記涨冀;3填硕、生物信息學(xué)入門學(xué)習(xí)資料及自己的學(xué)習(xí)筆記!