library(ggplot2)
# Simple: consistent font
ggplot(mtcars, aes(mpg, wt, color = factor(cyl))) +
geom_point() +
legend_style(size = 12, family = "serif")
# Styled title and keys
ggplot(mtcars, aes(mpg, wt, color = factor(cyl))) +
geom_point() +
legend_style(
size = 10,
title_size = 14,
title_face = "bold",
key_width = 1.5
)
# Full styling with background
ggplot(mtcars, aes(mpg, wt, color = factor(cyl))) +
geom_point() +
legend_style(
size = 11,
title_size = 13,
title_face = "bold",
key_fill = "grey95",
background = "white",
background_color = "grey80",
margin = 0.3
)
# Rotated labels for long category names
ggplot(mpg, aes(displ, hwy, color = class)) +
geom_point() +
legend_style(angle = 45)
# Style only the colour legend
ggplot(mtcars, aes(mpg, wt, color = factor(cyl), size = hp)) +
geom_point() +
legend_style(title_face = "bold", background = "grey95", by = "colour") +
legend_style(size = 10, by = "size")
Run the code above in your browser using DataLab