使用geom_histogram
时出现错误
unit(tic_pos.c, "mm") : 'x' and 'units' must have length > 0.
为什么?
p4<-ggplot(BCIcor,aes(x=cor))+geom_histogram(binwidth = 0.2)
这显示了一个黑色的条形图。但是,当我想要按p
对数据进行分组以使绘图更加丰富多彩时,我添加了fill=p
,
p4<-ggplot(BCIcor,aes(x=cor,fill=p))+geom_histogram(binwidth = 0.2)
我得到了以下信息:
error :"unit(tic_pos.c, "mm") : 'x' and 'units' must have length > 0".
怎么了??
数据帧为:
cor pvalue p
1 0.87882370 0.049710 2
2 -0.83041880 0.081660 1
3 -0.12989750 0.835100 1
4 -0.75309860 0.141700 1
5 -0.88553450 0.045680 2
发布于 2013-05-15 15:48:35
出现此错误是因为p
值在数据框中是数字的,但在本例中,对于fill=
,您需要离散值,因为条形图将根据p
进行堆叠和着色。只要在p
中使用as.factor()
即可。
ggplot(BCIcor,aes(x=cor,fill=as.factor(p)))+geom_histogram(binwidth = 0.2)
https://stackoverflow.com/questions/16569489
复制相似问题