2013-05-29 73 views
8

我試圖創建一個geom_bar有:如何解決'ymax未定義'?

<<boring-plots, fig.width=5, fig.height=5, out.width='.45\\linewidth',fig.show='hold', echo=FALSE, warning=FALSE>>= 
ma_at_vs_t_duh + geom_bar(stat="bin", fill="white", colour="darkgreen", width=.4)  + ggtitle("Anzahl MA nach Vertragsart, \nMandant 10 und 50") + 
theme(plot.title = element_text(lineheight=.6, face="bold")) + 
xlab("Vertragsart") + 
ylab("Anzahl MA") + 
theme(axis.title.x = element_text(vjust=0.5, size=14), axis.text.x=element_text(size=10)) + 
stat_bin(aes(label=..count..), geom="text", size=4, vjust=-0.5) 
@ 

編譯RNW-文件我得到的PDF輸出文件後:

ymax not defined: adjusting position using y instead 

我會很感激的任何幫助。謝謝!

+4

警告/消息來自ggplot並且是無害的。我不記得*確切地說*爲什麼會出現或者如何抑制它(''suppressMessages()'?set'message = FALSE' in'knitr' chunk options ?,但我經常見到它) –

+2

...在knitr chunk選項中設置'warning = FALSE'通常適用於我。 – joran

+0

warning = FALSE似乎無法在R 3.0.2版(2013-09-25)中使用knitr「3.0.1」 – skleene

回答

23

如果有人仍然對此感興趣,可以在ggplot的aes中添加ymax = max(value),這會使'ymax not defined'警告消失。

由於ymax用於定義barplot的最大「高度」,因此我建議將其設置爲比y軸上數據的最大值多一點。

事情是這樣的:

ggplot(df,aes(x=bla,y=blu,ymax=max(blu)*1.05))+geom_bar() 

1.05乘以爲您提供了註釋5%的喘息空間。

相關問題