user3115933
user3115933

Reputation: 4443

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) +
  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?

Upvotes: 4

Views: 18846

Answers (1)

Marco Sandri
Marco Sandri

Reputation: 24262

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

Upvotes: 8

Related Questions