Hi:

On Tue, Jan 4, 2011 at 6:56 PM, Eduardo de Oliveira Horta <
eduardo.oliveiraho...@gmail.com> wrote:

> Hello,
>
> this is probably a recurrent question, but I couldn't find any answers that
> didn't involve the expression "data frame"... so perhaps I'm looking for
> something new here.
>
> I wanted to find a code equivalent to
>
> > x=sqrt(1:10)
> > y=log(1:10)
> > plot(1:10, x, type="lines", col="darkgreen")
> > lines(1:10, y, col="red")
>
> to use with ggplot2. I've tried
>
> > x=sqrt(1:10)
> > y=log(1:10)
> > qplot(1:10, x, geom="line", colour=I("darkgreen"))
> > geom_line(1:10, y, colour="red")
> Error: ggplot2 doesn't know how to deal with data of class numeric
>

It would work in lattice, though:
xyplot(x ~ 1:10, type = 'l', col.line = 'darkgreen')

>
> but it seems that the "data frame restriction" is really very restrictive
> here. Any solutions that don't imply using as.data.frame to my data?
>

Please explain to me how

df <- data.frame(x, y, index = 1:10)
qplot(index, x, geom = 'line', ...)

is 'very restrictive'. Lattice and ggplot2 are *structured* graphics systems
- to get the gains that they provide, there are some costs. I don't perceive
organization of data into a data frame as being restrictive - in fact, if
you learn how to construct data for input into ggplot2 to simplify the code
for labeling variables and legends, the data frame requirement is actually a
benefit rather than a restriction. Moreover, one can use the plyr and
reshape(2) packages to reshape or condense data frames to provide even more
flexibility and freedom to produce ggplot2 and lattice graphics. In
addition, the documentation for ggplot2 is quite explicit about requiring
data frames for input, so it is behaving as documented. The complexity (and
interaction) of the graphics code probably has something to do with that.

Since Josh left you a quote, I'll supply another, from Prof. Steve Vardeman
in a class I took with him a long time ago:
"There is no free lunch in statistics: in order to get something, you've got
to give something up."

In this case, if you want the nice infrastructure provided by ggplot2, you
have to create a data frame for input.

Dennis

>
> Thanks in advance, and best regards!
>
> Eduardo Horta
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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.
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to