如何自定义向ggplot构面功能添加垂直线?

问题描述

我有一个数据集,其中每个物种都与另一物种的特定密度(数字)和类型(数字)混合。我想在ggplot中的每个facet_grid面板中添加两种垂直线: (a)固定密度/类型的固定线。例如1000/1 = 1000、1000 / 6 = 166.7、10000 / 1 = 10000、10000 / 6 = 1666.7

(b)直方图上叠加的每种处理的自举平均值和置信区间。 我尝试使用geom_vline添加均值,但似乎不正确。看起来所有手段都是一样的

set.seed(111)
count <- rbinom(500,100,0.1) 
species <- rep(c("A","B"),time = 250)
density <- rep(c("1000","10000","1000","10000"),time = 125)
type <- rep(c("1","1","6","6"),time = 125)
df <- data.frame(species,density,type,count) # I feel too naiive,but I'm not able to get all the treatments filled. Gah.

ggplot(df,aes(x= count,colour = species,fill = species)) + 
   geom_histogram(position="identity",alpha=0.5) + 
   theme_bw() + ylab("Frequency") + 
   facet_grid(species ~ type + density) + 
   theme(panel.grid.major = element_blank(),panel.grid.minor = element_blank()) +
   theme(legend.position = "none") + theme(aspect.ratio = 1.75/1) + 
   geom_vline(aes(xintercept=mean(count)),color="blue",linetype="dashed",size=1)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)