[R] ggplot legend for multiple time series

hadley wickham h.wickham at gmail.com
Tue Dec 1 21:45:15 CET 2009


Because of the combinatorial nature of ggplot2, it is simply not
possible to provide an example that illustrates every single
combination of options.  There are already over 600 example graphics
in the package - if you can't find one that exactly meets your need,
you need to buy the book and learn more about the rich theory
underlying the package.

Hadley

On Tue, Dec 1, 2009 at 2:02 PM, Edwin Sun <csun at cfr.msstate.edu> wrote:
>
> Hello - Thank you so much for the help. It works perfectly. I guess that as
> many have pointed out, ggplot is a great package but there is a lack of
> documentation and examples.
>
> Edwin Sun
>
>
> baptiste auguie-5 wrote:
>>
>> Hi,
>>
>> I don't understand why you used scale_manual_colour if you want only
>> black lines. To have different line types in the legend you can map
>> the linetype to the data,
>>
>>
>> huron <- data.frame(year=1875:1972, level=LakeHuron)
>>
>> ggplot(huron, aes(year)) +
>>    geom_line(aes(y=level+5, linetype="above")) +
>>    geom_line(aes(y=level-5, linetype="below")) +
>>    scale_linetype_manual("offset", c(1, 2))
>>
>> HTH,
>>
>> baptiste
>> 2009/12/1 Edwin Sun <csun at cfr.msstate.edu>:
>>>
>>> Hello All,
>>>
>>> I am trying to create a legend for a black-white graph. The package I use
>>> is
>>> ggplot2. It can add colors to the legend key but not line types. Can you
>>> please help?
>>>
>>> # example from Wickman (2009, ggplot2 – elegant graphics for data
>>> analysis,
>>> page 109)
>>>
>>> library(ggplot2)
>>> huron <- data.frame(year=1875:1972, level=LakeHuron)
>>> ggplot(huron, aes(year)) +
>>>    geom_line(aes(y=level+5, colour="above")) +
>>>    geom_line(aes(y=level-5, colour="below")) +
>>>    scale_colour_manual("Direction", c("above"="black", "below"="black"))
>>>
>>> Thanks,
>>>
>>>
>>> Edwin
>>>
>>> Changyou Sun, Ph.D.
>>> Associate Professor
>>> Natural Resource Policy & Economics
>>> Box 9681, Department of Forestry
>>> Mississippi State University
>>> Mississippi State, MS 39762
>>>
>>> #363 Thompson Hall
>>> (662) 325 7271 (ph), 325 8726 (fax)
>>> csun at cfr.msstate.edu
>>> www.cfr.msstate.edu/forestry
>>> --
>>> View this message in context:
>>> http://n4.nabble.com/ggplot-legend-for-multiple-time-series-tp932430p932430.html
>>> Sent from the R help mailing list archive at Nabble.com.
>>>
>>> ______________________________________________
>>> 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.
>>>
>>
>> ______________________________________________
>> 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.
>>
>>
>
> --
> View this message in context: http://n4.nabble.com/ggplot-legend-for-multiple-time-series-tp932430p932491.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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