library(ggplot2)
p <- ggplot(mpg, aes(displ, hwy, color = class)) +
geom_point() +
legend_style(angle = 45) +
labs(color = "Vehicle Class")
# Center title over keys only (long titles wrap automatically)
# Returns a gtable - use grid::grid.draw() to render
g <- center_legend_title(p)
grid::grid.draw(g)
Run the code above in your browser using DataLab