我正在尝试创建一个这样的情节:
qplot(carat, data = diamonds, geom = "histogram", fill = color)
然而,我没有使用x轴的定量变量,而是使用分类数据。我正在使用这样的数据框:
refBases=c("A","A","A","C","C","C","G","G","G","T","T","T")
altBases=c("C","G","T","A","G","T","A","C","T","A","C","G")
myDF$ref=refBases
myDF$alt=altBases
myDF$Freq=c(5,2,3,6,9,6,8,6,7,4,6,4)
所以,基本上,我希望我的情节看起来一样,只是x轴将是ref列的四个区(A,C,G,T); y轴将是Freq;并且颜色图例将是alt列(A,C,G,T)中的四个变量。因此,基本上,x轴上将有四个参考箱,每个参考箱沿y轴分为三个部分,颜色图例表示alt值。
当我尝试我期望的时候,我得到一些相当愚蠢的东西:
qplot(ref,Freq,data=myDF,fill=alt)
答案 0 :(得分:0)
你所描述的并不像直方图(这是连续随机变量估算核密度的一个非常具体的图);听起来你只想要一个条形图。我相信这就是你要找的东西
myDF <- data.frame(
ref=c("A","A","A","C","C","C","G","G","G","T","T","T"),
alt=c("C","G","T","A","G","T","A","C","T","A","C","G"),
Freq=c(5,2,3,6,9,6,8,6,7,4,6,4)
)
library(ggplot2)
ggplot(myDF, aes(ref, Freq, fill=alt)) +
geom_bar(stat="identity", position="dodge")