library(ggplot2)
# Legend with rotated text that might overflow
p <- ggplot(mpg, aes(displ, hwy, color = class)) +
geom_point() +
legend_style(angle = 90)
# Auto-fit will wrap if needed
legend_auto_fit(p)
Run the code above in your browser using DataLab