Home > Back-end >  Set legend width to be 100% plot width
Set legend width to be 100% plot width

Time:02-11

How do I set the legend height or width to be 100% of the plot height/width regardless of the actual dimensions?

library(ggplot2)
ggplot(iris, aes(Petal.Width, Sepal.Width, color=Petal.Length)) 
  geom_point() 
  theme(
    legend.title=element_blank(),
    legend.position="bottom",
    legend.key.width=unit(0.1,"npc"))

Created on 2022-02-11 by the legend_barwidth

  • Related