Skip to content
Prev 246427 / 398502 Next

Adding lines in ggplot2

Hi Eduardo,

To shamelessly borrow from the Princess Bride:

?Why do you use a data frame? Are you touched in the head?
"Oh no. It's just they're terribly practical. I think everyone will be
using them in the future.?

Using data frames is what Hadley intended, and once you get used to
it, it is not nearly as restrictive as you might think.  This does
what you want, I believe.  Rather than creating extraneous variables,
I simply perform various transformations on 'x' within the plotting
code.

require(ggplot2)
dfm <- data.frame(x = 1:10)

qplot(x = x, y = sqrt(x), data = dfm, geom = "line",
  colour = I("darkgreen")) +
  geom_line(aes(x = x, y = log(x)), colour = "red")

Cheers,

Josh


On Tue, Jan 4, 2011 at 6:56 PM, Eduardo de Oliveira Horta
<eduardo.oliveirahorta at gmail.com> wrote:
#####
note you would also need a + after the qplot() code to add geom_line()
#####