[R] ggplot2 legend for vertical lines

hadley wickham h.wickham at gmail.com
Thu Jul 3 15:44:01 CEST 2008


Hi Baptiste,

I've fixed this problem in the development version and you can work
around it in the cran version as follows:

ggplot(dfr, aes(fact2, values)) +
geom_point(aes(colour = fact)) +
geom_vline(intercept = 5)

(i.e. make sure the vline never sees that colour has been mapped to an
aesthetic)

Hadley


On Thu, Jul 3, 2008 at 3:01 AM, baptiste Auguié <ba208 at exeter.ac.uk> wrote:
> Dear all,
>
>
> The following example code produces a graph with ggplot2, to which I add
> several vertical lines of arbitrary colors. I am not satisfied with the
> legend: it automatically adds some vertical lines which I'd rather not see
> (they confuse the reader rather than add information in this case).
>
>> library(ggplot2)
>> dfr <- data.frame(values = sin(1:50/10),
>>        fact = rep(c("short", "long"), each=25, length=50),
>>        fact2 = rep(1:10,  length=50))
>>
>> p <- qplot(fact2, values, data=dfr, colour=fact)
>> p + geom_vline(intercept=c(5), colour = 1) +
>> scale_shape_manual(name="fact", values=1) # tried this, but useless here
>
>
> Any tips on changing these settings would be welcome!
>
>
> Sincerely,
>
> baptiste
> _____________________________
>
> Baptiste Auguié
>
> Physics Department
> University of Exeter
> Stocker Road,
> Exeter, Devon,
> EX4 4QL, UK
>
> Phone: +44 1392 264187
>
> http://newton.ex.ac.uk/research/emag
> http://projects.ex.ac.uk/atto
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
http://had.co.nz/



More information about the R-help mailing list