8

I'm trying to create a geom_bar with:

<<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) 
@

After compiling the Rnw-File I'm getting in the pdf-output file:

ymax not defined: adjusting position using y instead

I'd appreciate any help. thanks!

joran
  • 169,992
  • 32
  • 429
  • 468
SebastianS
  • 477
  • 7
  • 14
  • 4
    The warning/message is coming from ggplot and is harmless. I don't remember *exactly* why it occurs or how to suppress it (`suppressMessages()`? set `message=FALSE` in the `knitr` chunk options?, but I've seen it often) – Ben Bolker May 29 '13 at 18:36
  • 2
    ...and setting `warning = FALSE` in the knitr chunk options usually works for me. – joran May 29 '13 at 18:38
  • warning=FALSE doesn't appear to work in R version 3.0.2 (2013-09-25) with knitr "3.0.1" – skleene Jun 13 '14 at 11:06
  • Setting knitr chunk option `warning=FALSE` didn't work for me but `message=FALSE`. knitr_1.10.5 & R version 3.2.0 on OS X – arvi1000 Dec 17 '15 at 20:57

1 Answers1

24

If anyone is still interested in this, you can add ymax = max(value), in the aes of ggplot, and that will make the 'ymax not defined' warning to go away.

Since ymax is used to define the max 'height' of a barplot for example, I would recommend to set to a bit more than the maximum value of your data in the y axis.

Something like this:

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

Multiplying by 1.05 gives you 5% breathing room for annotation.

David Arenburg
  • 91,361
  • 17
  • 137
  • 196
Slak
  • 578
  • 10
  • 13