I am plotting a number of data sets using ggplot2 in R. To make the plots easier to compare, I am setting the limits of the y-scale, but, it turns out, nothing is plotted above the ‘natural top’ of the plot.
eg for this plot:

(source: sickel.net)
I have tried to set the top y-value to 500 (and looking at the white space at the top, I have managed to) but how to make ggplot also plot the labels for 400,450 and 500 and the corresponding grid lines?
the data are in the dataframe df with df$dataset and df$error as data and error-level respectively. My plotting code presently is
max = max(df$dataset + df$error) * 1.05
if(max > 300) max=505
dataplot = ggplot(data=df, aes(x=species,y=dataset,fill=dim,ylim=c(0,max)))
dataplot = dataplot+geom_bar(position=position_dodge())
dataplot = dataplot+scale_fill_manual(values=c("#BBBBBB", "#444444"))
dataplot = dataplot + ylab(ylab) + xlab(xlab) + opts(legend.title=theme_blank())
limits <- aes(ymax = df$dataset+df$error, ymin=df$dataset-df$error)
dodge = position_dodge(width=0.9)
dataplot = dataplot + geom_errorbar(limits, position=dodge, width=0.5)
dataplot = dataplot + opts(panel.background = theme_rect(fill='white', colour='white'))
dataplot = dataplot + opts(panel.grid.major = theme_line(colour = "gray"))
# dataplot = dataplot + coord_cartesian(ylim=c(0, max))
# dataplot = dataplot + scale_y_continuous(limits=c(0, max))
dataplot = dataplot +
opts(axis.text.x = theme_text(colour = "black",angle=90),
axis.text.y = theme_text(colour = "black"))
dataplot = dataplot + opts(legend.key.size = unit(0.3, "cm"))
print(dataplot)
As can be seen from the commented out lines, I have tried coord_cartesian, scale_y_continous as well as the present y-lim without any luck (yes, and I know that coord_cartesian is zooming in)
For the ylimits you can add:
In order to set the tick points, you can use:
Therefore, I think you need to add the code below to your plot code: