user3115933 user3115933 - 3 months ago 27
R Question

Using ggplot2, how to set the Tick Marks intervals on y-axis without distorting my Boxplot?

I am using ggplot2 to create a Box Plot chart. My R codes stand as follows:

ggplot(mydata4, aes(PropertyCode,Total.Extras.Per.GN, fill=Original.Meal.Plan.Code))+
geom_boxplot(outlier.shape=NA) +

This gives me the following output:

Boxplot 1

However after adding the following line of code to my existing codes, I end up with Figure 2 (shown below):

+ scale_y_continuous(breaks = seq(0, 1000, by=100))

Boxplot 2

As you can see, it distorts the whole graph. How do I go about maintaining my chart as Figure 1 and yet have the proper intervals displayed on the y-axis?

Answer Source

A solution is to substitute ylim(c(0,1000))+scale_y_continuous(breaks = seq(0, 1000, by=100)) with scale_y_continuous(breaks = seq(0, 1000, by=100), limits=c(0,1000)):

ggplot(mydata4, aes(PropertyCode,Total.Extras.Per.GN, fill=Original.Meal.Plan.Code)) + 
geom_boxplot(outlier.shape=NA) + 
scale_y_continuous(breaks = seq(0, 1000, by=100), limits=c(0,1000))