问题描述
当使用 geom_histogram
时,出现错误
单位(tic_pos。 c,mm):'x'和'单位'必须有长度> 0.
为什么?
p4
这显示了一张黑色条形图。然而,当我想按照 p
对数据进行分组以使色彩丰富时,我添加了 fill = p
,
p4
我得到以下结果:
错误:unit(tic_pos.c,mm):'x'和'units'的长度必须> 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
你得到这个错误是因为在你的数据框中 p
值是数字,但在这种情况下,对于 fill =
当条被堆叠时,您需要离散值,并根据 p
进行着色。只需使用 as.factor()
围绕 p
。
<$ (b = c,fill = as.factor(p)))+ geom_histogram(binwidth = 0.2)
pre>
When using geom_histogram
there is error
unit(tic_pos.c, "mm") : 'x' and 'units' must have length > 0.
Why?
p4<-ggplot(BCIcor,aes(x=cor))+geom_histogram(binwidth = 0.2)
This showed a black bar chart. However, when I wanted to group the data by p
to make the plot colorful, I added fill=p
,
p4<-ggplot(BCIcor,aes(x=cor,fill=p))+geom_histogram(binwidth = 0.2)
The I got the following:
error :"unit(tic_pos.c, "mm") : 'x' and 'units' must have length > 0".
What's wrong??
The data frame is:
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
You got this error because p
values are numeric in your data frame but in this case for the fill=
you need discrete values as bars are stacked and will be colored according to p
. Just use as.factor()
around p
.
ggplot(BCIcor,aes(x=cor,fill=as.factor(p)))+geom_histogram(binwidth = 0.2)
这篇关于当使用“geom_histogram”时,有错误“单位(tic_pos.c,”mm“):'x'和'单位'必须有长度> 0" ;.为什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!