Re: [R] Combining several mappings in ggplot2

From: Tribo Laboy <tribolaboy_at_gmail.com>
Date: Wed, 26 Mar 2008 20:01:08 +0900

Apologies! I though that the Orange dataset comes with R, but it is in fact in the package "datasets".

So here's another "Orange2" dataset for the example:

Tree_v = rep(c(1:5),each = 5)
age_v = rep(seq(1,25, by = 5),5) + 10*runif(25) circumference_v <- rep(seq(21,45, by = 5), 5)*Tree_v + 25*runif(25) Orange2 <- data.frame(Tree = as.factor(Tree_v), age = age_v, circumference = circumference_v)

This works fine:

ggplot(data = Orange2, aes(x = age, y = circumference, color = Tree)) + geom_line()

These generate errors (included):

> ggplot(data = Orange2, aes(x = age, y = circumference, color = Tree, linetype = Tree)) + geom_line()
Error in get("check_domain", env = ., inherits = TRUE)(., ...) :   Too many values in domain (5 > 4)

> ggplot(data = Orange2, aes(x = age, y = circumference, color = Tree)) + geom_line() + scale_linetype_manual(value = c(1:5))
Error in unit(values, units, data = data) :   'x' and 'units' must have length > 0

What am I doing wrong?

Regards,

TL

On Wed, Mar 26, 2008 at 2:08 AM, hadley wickham <h.wickham_at_gmail.com> wrote:
> On Tue, Mar 25, 2008 at 11:48 AM, Tribo Laboy <tribolaboy@gmail.com> wrote:
> > Hello,
> >
> > I want to be able to make a plot that has several series with
> > different color and linetype.
> > Online documentation suggest that this is possible, but I haven't found how:
> >
> > "We can also create redundant mappings, mapping the same variable to
> > multiple aesthetics. This is most useful when producing a graphic for
> > both colour and black and white display."
> >
> > Here's what I have to get the color
> > ggplot(data = Orange, aes(x = age, y = circumference, color = Tree)) +
> > geom_line()
> >
> > if i try this I get an error:
> > ggplot(data = Orange, aes(x = age, y = circumference, color = Tree,
> > linetype = Tree)) + geom_line()
>
> Please provide a reproducible example (or at least describe the
> error!), otherwise we have no way to help you.
>
> Hadley
>
>
> --
> http://had.co.nz/
>



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. Received on Wed 26 Mar 2008 - 11:10:04 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 27 Mar 2008 - 06:30:28 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive