当使用“geom_histogram”有错误“单元(tic_pos.c中,” mm“):‘x’和‘

2019-09-03 10:09发布

当使用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

Answer 1:

因为你得到这个错误p值数值在数据帧,但在这种情况下,对于fill=你需要离散值条堆叠,并将根据着色p 。 只要使用as.factor()围绕p

ggplot(BCIcor,aes(x=cor,fill=as.factor(p)))+geom_histogram(binwidth = 0.2)


文章来源: When using “geom_histogram” there is error “unit(tic_pos.c, ”mm“) : 'x' and 'units' must have length > 0”. Why
标签: r ggplot2