I have this data frame:
> str(DF)
'data.frame': 14084 obs. of 6 variables:
.
.
.
$ Variables: chr "Height" "Height" "Height" "Height" ...
$ Values : num 245 129 301 162 123 125 115 47 46 135 ...
$ Year : Factor w/ 2 levels "2015","2016": 1 1 1 1 1 1 1 1 1 1 ...
I wrapped the plot in two facets (in two columns) using facet_wrap()
with free axes scales.
ggplot(data = DF, aes(x = Year, y = Values)) +
geom_boxplot() +
facet_wrap("Variables", scales = "free")
My problem is:
Both the facets share a common y-axis title. What I would like, however, is two separate y-axis titles for the two facets. A common x-axis title is fine for me.
I came across this question Showing different axis labels using ggplot2 with facet_wrap but it does not solve the problem the way I want as I do not want to lose the facet labels on top. Moreover, my facets are arranged horizontally.
I tried using labs()
:
. . . +
labs(y=c("A", "B"))
But it just changes the y-axis title of first facet to A
and the second facet remains as it is.
How could I address this problem?
Any help would be appreciated.