Legend Legend - 8 months ago 102
R Question

Any way to extend the line in the legend?

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.

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download