2013-09-27 326 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