在一个图中组合 geom_vridgeline 和 geom_line
Combining geom_vridgeline with geom_line in one plot
我想将 geom_vridgeline 与(连接的)折线图结合起来。
geom_line(和 geom_point)的值来自不同的数据集。 IE。它不是 geom_vridgeline.
中使用的观察值的时刻(平均值、中值等)
我尝试了简单的 geom_vridgeline(...) + geom_line(data...)+geom_point(..) 以及一些调整(添加第二个x 轴等)。
library(tidyverse)
library(ggridges)
#The original chart
ggplot(iris, aes(x=Species, y=Sepal.Width, width = ..density.., fill=Species)) +
geom_vridgeline(stat="ydensity", trim=FALSE, alpha = 0.85, scale = 0.25)
# another dataset
df<-iris%>%
group_by(Species)%>%
summarise(newvar=mean(Sepal.Width))
# add line from new dataset (doesn't work)
ggplot(iris, aes(x=Species, y=Sepal.Width, width = ..density.., fill=Species)) +
geom_vridgeline(stat="ydensity", trim=FALSE, alpha = 0.85, scale = 0.25)+
geom_line(data=df,aes(x=factor(Species),y=newvar))
像这样
https://www.dropbox.com/s/1v7ycl23014hau8/Rplot.png?dl=1
注意:在我的真实示例中,x 轴实际上是连续的。我假设一旦我弄清楚如何添加 geom_line 我也可以添加 geom_point
非常感谢!
ggplot() +
geom_line(data=df,mapping=aes(x=Species,y=newvar,group = 1)) +
geom_vridgeline(data=iris, aes(x=Species, y=Sepal.Width, width = ..density.., fill=Species),stat="ydensity", trim=FALSE, alpha = 0.85, scale = 0.25)
我想将 geom_vridgeline 与(连接的)折线图结合起来。
geom_line(和 geom_point)的值来自不同的数据集。 IE。它不是 geom_vridgeline.
中使用的观察值的时刻(平均值、中值等)我尝试了简单的 geom_vridgeline(...) + geom_line(data...)+geom_point(..) 以及一些调整(添加第二个x 轴等)。
library(tidyverse)
library(ggridges)
#The original chart
ggplot(iris, aes(x=Species, y=Sepal.Width, width = ..density.., fill=Species)) +
geom_vridgeline(stat="ydensity", trim=FALSE, alpha = 0.85, scale = 0.25)
# another dataset
df<-iris%>%
group_by(Species)%>%
summarise(newvar=mean(Sepal.Width))
# add line from new dataset (doesn't work)
ggplot(iris, aes(x=Species, y=Sepal.Width, width = ..density.., fill=Species)) +
geom_vridgeline(stat="ydensity", trim=FALSE, alpha = 0.85, scale = 0.25)+
geom_line(data=df,aes(x=factor(Species),y=newvar))
像这样
https://www.dropbox.com/s/1v7ycl23014hau8/Rplot.png?dl=1
注意:在我的真实示例中,x 轴实际上是连续的。我假设一旦我弄清楚如何添加 geom_line 我也可以添加 geom_point
非常感谢!
ggplot() +
geom_line(data=df,mapping=aes(x=Species,y=newvar,group = 1)) +
geom_vridgeline(data=iris, aes(x=Species, y=Sepal.Width, width = ..density.., fill=Species),stat="ydensity", trim=FALSE, alpha = 0.85, scale = 0.25)