[英]How to draw Density Plot of two groups in R
I have a dataframe with few lines shown below: 我有一个数据框,下面显示了几行:
AlleleFrequency Region
0.0451128 intergenic
0.0451128 intergenic
0.0075188 Genic
0.0037594 intergenic
0.0263158 Genic
I would like to get a plot as shown below with density on Y-axis and X-axis with allele frequencies of the two groups "intergenic" and "Genic" colored differently. 我想得到一个如下图所示,Y轴和X轴上的密度,两组“基因间”和“基因组”的等位基因频率用不同的颜色着色。 Could someone help? 有人可以帮忙吗?
I tried with the below function. 我尝试了以下功能。
ggplot(DEL, aes(AFS_adj, fill = Genic)) + geom_density(alpha = 0.5) + scale_x_continuous(limits = c(0, 0.5))
which does not give the desired output. 不能提供所需的输出。
ggplot(DEL,aes(x=AlleleFrequency,y=..density..,fill=Region))+
geom_histogram(position="dodge")+ scale_fill_manual(values=c("red","black"))
Varying the binwidth
argument of geom_histogram
you can make the plot look like the one you want to achieve 改变binwidth
的说法geom_histogram
可以使剧情看起来像你想达到的一个
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.