2013-09-27 93 views
0

我在使用当前数据集创建我需要的barplot时遇到了很多麻烦。看起来很直截了当,但是每当我运行我的代码时我都会收到错误信息。R:创建描绘ggplot2中百分比的百分比的barplot

link to my data set

一些背景信息

Percent_Calls由

Percent_Total由(呼叫+噪声)/(总和(呼叫)来计算呼叫/(呼叫+噪声)来计算+总和(噪声));

PercentofCall由Percent_Calls * Percent_Total

我正在与CRF_Score试图创建一个barplot(与y轴的百分比)为x变量和Percent_Total值作为条计算的。最后,我想突出Percent_Total中PercentofCall的部分。

require(ggplot2) 
ggplot(FD2_CAna, aes(CRF_Score, fill=Percent_Total)) + geom_bar(binwidth=0.05) 

上面的代码通常是对我的作品,但我得到这个错误,而不是:

Error in unit(tic_pos.c, "mm") : 'x' and 'units' must have length > 0 

我一直在使用as.factor(x)在另一个线程建议尝试,但图形输出是不是我所需要。

It's showing me a gradient of values, and I only need the value as seen in the data.frame to be plotted

这是一起的我想要什么线比较多,除了它是在JMP制作。 enter image description here

对不起,很长的解释,我在这里做错了什么?

回答

1

要获得类似的情节JMP你应该使用Percent_Total作为y值,而不是作为fill=值,然后在geom_bar()使用stat="identity"

对于你的JMP图,看起来Percent_Total被视为因子而不是数值变量 - 你可以通过比较块的高度和值23和2来看到它 - 它们几乎是相同的宽度。如果文件FD2_CAna.csv正确导入,则值是数字。

FD2_CAna<-read.csv2(file="FD2_CAna.csv",header=T,sep=",",dec=".") 
ggplot(FD2_CAna, aes(CRF_Score, Percent_Total)) + geom_bar(stat="identity") 

enter image description here

+0

这完美的作品,谢谢。我应该更仔细地阅读ggplot包的信息。 – Mengll