I would like to access only of the legend below, carb and setting the font size to 20. How can I do that. The code below changes both legends.
library(tidyverse)
ggplot(mtcars, aes(x = mpg, y = disp, color = carb, shape = as.factor(am))) +
geom_point() +
theme(legend.title = element_text(size = 20))
>Solution :
You can set individual theme elements for a legend inside the function guides(). In your case, the legend for carb is a colorbar mapped to the color aesthetic, so we can do
ggplot(mtcars, aes(x = mpg, y = disp, color = carb, shape = as.factor(am))) +
geom_point() +
guides(color = guide_colorbar(
theme = theme(legend.title = element_text(size = 20))
)
)
