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

10,474

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))
Share:
10,474
user3115933
Author by

user3115933

Updated on June 30, 2022

Comments

  • user3115933
    user3115933 almost 2 years

    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) +
      ylim(c(0,1000))
    

    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?

    • user3115933
      user3115933 almost 7 years
      Thanks. Exactly what I needed. If you post as an answer, I;ll give it my vote.