I draw lines with ggplot2 as follows:
ggplot(iris, aes(Petal.Width,Petal.Length,color=Species)) + geom_line() + theme_bw()
.
I believe that legend labels are small, so I want them to be larger. If I change the size, the lines in the plot also change:
ggplot(iris, aes(Petal.Width,Petal.Length,color=Species)) + geom_line(size=4) + theme_bw()
.
But I want to see only thick lines in the legend, I want the lines on the plot to be thin. I tried using legend.key.size , but it changes the square of the label, not the line width:
library(grid) # for unit ggplot(iris,aes(Petal.Width,Petal.Length,color=Species))+geom_line()+theme_bw() + theme(legend.key.size=unit(1,"cm"))

I also tried using dots:
ggplot(iris,aes(Petal.Width,Petal.Length,color=Species)) + geom_line() + geom_point(size=4) + theme_bw()
But, of course, this still affects both the plot and the legend:

I wanted to use lines for the plot and dots / dots for the legend.
So, I ask about two things:
- How to change the line width in a legend without changing the graph?
- How to draw lines in a plot, but draw dots / dots / squares in a legend?
r plot ggplot2 legend
baltazar May 03 '13 at 9:48 a.m.
source share