STHDA forum

Plotting, data visualizations » ggplot2:Defining different y-axis limits in the same boxplot graph when using 2 facets

Slingshot booster



Signed up since: 22/09/2017

Messages: 1

On 09/22/2017 at 10h29
Hi all,

I want to produce a boxplot graph with two facets that have different y limits using the ylim() function.
How do I specify the y-axis range of the first (e.g., ylim(0, 2.5)) and the second facet (e.g., ylim (0,0.4)) in the facet command?

At the moment, my script looks like this:

p <- ggplot(OVLP, aes(x=Month, y=Ovlp, fill=Level)) +
geom_boxplot(fill="white", width = 0.5)+
geom_dotplot(binaxis='y', stackdir='center', dotsize = 1, position = position_jitter(0.1)) +
labs(title = "2010", x="\nMonth", y = "UDOI\n") +
scale_fill_manual(values=c("#2ca25f", "#feb24c"))+
scale_x_discrete(limits=c("May","Jun","Jul","Aug", "Sep", "Oct", "Nov"))+
facet_grid(Isopleth_f ~ ., scales='free')+

p + theme(axis.title.x = element_text(size=16),
axis.title.y = element_text(size=16),
axis.text.x = element_text(size=14, color = "black"),
axis.text.y = element_text(size=14, color = "black"),
legend.title = element_text(colour="black", size=16),
legend.text = element_text(colour="black", size=14),
strip.text.x = element_text(size=12, face="bold"),
strip.text.y = element_text(size = 12, face = "bold"))

I would like to produce separate boxplots for different years while maintaining the same ylims for the first and second facets.

Thanks in advance!

You aren't allowed to write in this category
1 User online : 0 Administrator, 0 Moderator, 0 Member and 1 Visitor
User online : No member online