ggplot2:在 facet_grid 中按组添加水平线

问题描述

我想按组绘制带有水平线的点图。 df 对象存储点,df.line 对象存储我想添加到点图中的线。水平线不是点的均值/中值,它们是我想在这个图中展示的一些标准。

我尝试了 gome_hlinegeom_linegeom_errorbarstat_summary。但它们都不是我想要的。

谁能教我怎么做?

library(ggplot2)
library(tidytext)
set.seed(42)
df=data.frame(site=c(rep("a",5),rep("b",rep("c",5)),sample=c(1:5,1:5,1:5),value=c(runif(5,min=0.54,max=0.56),runif(5,min=0.52,max=0.6),min=0.3,max=0.4)),condition=c(rep("c1",rep("c2",5)))
df.line=data.frame(site=c("a","b","c"),standard=c(0.55,0.4,0.53))
ggplot(df)+
geom_point(aes(x=tidytext::reorder_within(site,value,condition,fun=mean),y=value))+
facet_grid(~condition,space="free_x",scales = "free_x")+
scale_x_reordered()

img

解决方法

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

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

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