First, as your y data are continuous you should use scale_y_continuous()
. In this function you can add argument breaks= pretty_breaks()
(add library scales
to use function pretty_breaks()
). If you don't provide any number inside pretty_breaks()
then in this case you will get integer numbers on y axis. You can set number of breaks to display, for example, pretty_breaks(4)
but for the first facet where you have range 0-10 it will still display only integer values and the number of breaks will be larger to get "nice" numbers.
library(scales)
ggplot(data=chart.data,aes(x=x,y=y)) +
geom_bar(stat="identity") +
facet_wrap(facets=~group,nrow=1,scale="free_y")+
scale_y_continuous(breaks= pretty_breaks())