Any way to expand the line in the legend?

Let's say I have the following graph built using ggplot:

enter image description here

Is it possible to increase the length of a string in a legend? Sometimes it is simply impossible to determine which line corresponds to that line on the chart using the legend.

+5
source share
2 answers

there is an option here legend.key.width:

# sample data frame
df <- data.frame(x = c(rnorm(100, -3), rnorm(100), rnorm(100, 3)), 
                 g = gl(3, 100))
df <- ddply(df, .(g), summarize, x = x, y = ecdf(x)(x))

ggplot(df, aes(x, y, colour = g, linetype = g)) + 
    geom_line() + 
    theme(legend.key.width = unit(10, "line"))

enter image description here

+9
source

optsdoes not work with ggplot2. You need to use theme, so instead you need to enter:

+ theme(legend.key.width = unit(10, "line"))
0
source

All Articles