【发布时间】:2021-07-13 03:52:55
【问题描述】:
我有两个来自不同长度的数据帧的 ggplots,我分别绘制了一列的直方图,如下所示。我想将这两个图组合成一个具有两个不同 y 轴的 ggplot,一个在右侧,一个在左侧,用于两个数据帧。我该怎么做?
a = ggplot(GG, aes(x = as.numeric(Kstat))) +
theme_pubclean()
a + geom_density() +
geom_vline(aes(xintercept = mean(Kstat)),
linetype = "dashed", size = 0.6) + xlim(0,1000)+ylim(0,0.1)
b = ggplot(all, aes(x = as.numeric(Kstat))) +
theme_pubclean()
b + geom_density() +
geom_vline(aes(xintercept = mean(Kstat)),
linetype = "dashed", size = 0.6) + xlim(0,1000)+ylim(0,0.5)
【问题讨论】:
-
没有时间研究示例。查看r-graph-gallery.com/line-chart-dual-Y-axis-ggplot2.html。请注意,虽然可行,但请考虑将 2 个图表并排放置是否能以更好的方式传达您的信息。
-
把你的数据变成长格式,然后刻面你想比较的图。如果您可以为两个数据框添加一些示例数据,这将有助于测试和验证解决方案。使用
dput(your_dataframe)将您的数据粘贴到问题中minimal reproducible example 提供了一些关于提出好问题的提示。
标签: r ggplot2 plot histogram density-plot