Adjust key width and key height of legend in ggplot2


When points are superimposed on lines, and the linetype is legended, then the points make difficult to identify the linetype in the legend.

ggplot2 has an option to adjust key width and key height.

 

Data and a basic layer:

d <- data.frame(g=gl(4,5), x=rep(1:5, 4), y=runif(4*5))
p <- ggplot(d, aes(x, y, linetype=g, shape=g, colour=g)) + geom_line() + geom_point()

 

Wide key makes easy to identify the linetype:

p + opts(legend.key.width=unit(3,"line"))


 

Probably useless…

p + opts(legend.key.height=unit(3,"line"))

2 thoughts on “Adjust key width and key height of legend in ggplot2

  1. Pingback: r - Is there a way to change the spacing between legend items in ggplot2? - Stack Overflow

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s