Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any way to extend the line in the legend?

Tags:

r

ggplot2

Let us say I have the following graph plotted using ggplot:

enter image description here

Is there anyway to extend how much line length is displayed in the legend? Sometimes, it just gets impossible to identify which line correspond to which line in the graph using the legend.

like image 333
Legend Avatar asked Oct 02 '11 03:10

Legend


1 Answers

here is an option 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

like image 180
kohske Avatar answered Sep 18 '22 12:09

kohske