我正在使用 ggplot 创建直方图 + 密度曲线的分面包装。这是我正在绘制的数据框(约 300 行):
head(merged)
# tpl strand base score ipdRatio motif
# 1 24501 0 A 51 3.108 AAGTACTCG
# 2 58809 0 A 69 4.095 GAGTACTAC
# 3 65614 0 A 61 3.341 TAGTACTCA
# 4 78494 0 A 92 4.968 GAGTACTAC
# 5 92127 0 A 23 1.702 AAGTACTTA
# 6 193102 0 A 96 5.255 GAGTACTCG
这是 csv 文件的链接,以便您可以自己读取数据框:dropbox 链接
如果我尝试这个,除了在 geom_histogram 中指定的 binwidth 之外什么都没有:
# Graph Histogram
ggplot(merged, aes(score)) +
geom_histogram(binwidth=25) +
geom_density() +
facet_wrap(~ motif,ncol=7) +
labs(title=paste("MOTIF:",motif_f),x="Methylation Score",y="Frequency")
但是,如果我尝试通过aes(y=..density..)
像这样添加到 geom_histogram 来为每个单独的图创建密度图:
# Graph Histogram
ggplot(merged, aes(score)) +
geom_histogram(aes(y=..density..),binwidth=25) +
geom_density() +
facet_wrap(~ motif,ncol=7) +
labs(title=paste("MOTIF:",motif_f),x="Methylation Score",y="Frequency")
我得到了一个不想要的结果,其中 y 参数对于某些图被拉伸,而对于其他图则狭窄:
关于如何在这些图上叠加密度图同时保持与第一张图像中相同的 y 参数的任何建议?