[R] How to set colors, axis gap, and free scale in ggplot?

Ron Crump r@e@crump @end|ng |rom w@rw|ck@@c@uk
Tue Feb 22 12:41:47 CET 2022


Hi Luigi,

> # FROM HERE IT DOES NOT WORK
> facet_grid(. ~ Species, scales="free_y") + # THE SCALE IS FIXED FOR ALL PANELS

I don't think you can force facet_grid to do this: the y scale will
always be fixed within a row (unless someone else tells you differently,
I may have misunderstood this)  - this is to allow easy comparison and,
consequently, comprehension of the graphic as you scan across a row.

You can achieve what you want with:
facet_wrap(~ Species, nrow = 1, scales = "free_y")
but for the reason above, I'm not sure it's a good thing to do.

> scale_colour_manual(values = c("palegreen4", "orangered3")) # THE
> COLORS ARE AUTOMATIC

You're setting the colour manually - which relates to lines, not fill
and you have no colour aesthetic set, just a fill one.

Use scale_fill_manual(values = c("palegreen4", "orangered3")) instead.

> I would also like to increase the size of the axis labels and the
> title size of the panels.
> What is the correct syntax?

See ?theme - you are interested in axis.title (maybe axis.title.x,
axis.title.y) and strip.text (the labels for the facets). See also
?element_text as in theme, you basically want to put something like
axis.title = element_text(...), replacing ... with the settings you
want.

For help specifically on ggplot2 and other tidyverse packages, I'd
recommend using https://community.rstudio.com in the future.

Best wishes,
Ron.



More information about the R-help mailing list