如何解决“ymax未定义”的问题?

8

我正在尝试创建一个geom_bar,其中包括:

<<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()?在knitr块选项中设置message=FALSE?但我经常看到它)。 - Ben Bolker
2
通常在knitr代码块选项中设置warning = FALSE对我来说是有效的。 - joran
在R版本3.0.2(2013-09-25)中,使用knitr“3.0.1”时,warning = FALSE似乎无效。 - skleene
设置 knitr 块选项 warning=FALSE 对我无效,但 message=FALSE 有效。knitr_1.10.5 & R 3.2.0 版本在 OS X 上。 - arvi1000
1个回答

24
如果有人仍然感兴趣,您可以在ggplot的aes中添加ymax = max(value),这将使“ymax未定义”的警告消失。
由于ymax用于定义例如条形图的最大“高度”,因此我建议将其设置为比y轴上数据的最大值略高一些。
类似于这样:
ggplot(df,aes(x=bla,y=blu,ymax=max(blu)*1.05))+geom_bar() 

乘以1.05会为您的注释留出5%的余地。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接