Re: [R] ggplot2 argument handling odd

From: Sebastian Weber <sebastian.weber_at_physik.tu-darmstadt.de>
Date: Mon, 31 Mar 2008 09:36:24 +0200

Hi Hadley,

I tried today your solution to this problem. However, the finally working code was like

eval(substitute(ggplot( aes_string(...) ))

The qplot code below did not work at all, neither works a

ggplot(aes_string(...))

BTW: Since I am always writing scripts to produce my plots, how can I split accross multiple lines one command in a R-script? These ggplot commands can become rather long and the syntax

pl <- ggplot( ........... long expression ................. )
pl <- pl + some_layer( ........... )

is not very intuituve. So, how do I break lines in R-Scripts.

These questions must sound like beginner questions - but I have searched archives and documentation without success. As we speak of it - is your book finally out?

Greetings,

Sebastian Weber

On Thu, 2008-03-27 at 07:57 -0500, hadley wickham wrote:
> > Ok, I will try that, thanks. BTW, where is this aes_string option
> > documented, sounds useful? How could I do the same thing with facetting?
> > If I want to save something like ". ~ groupVar" as a string in a
> > variable, could I pass it with facet_string to ggplot?
>
> It's a see also from ?aes (or at least it is in the development
> version). facet_grid should already accept a string instead of a
> function, so it should just work.
>
> > But anyway, I would be curious how to do it with qplot. The basic
> > question is: How to pass the string of a variable to a function which is
> > supposed to interpret it. Aka:
> >
> > var <- "magicVar"
> >
> > fun(doSomeMagic(var))
> >
> > doSomeMagic should then write magicVar at the place.
>
> In general, you can use as.name, substitute and eval:
>
> x <- as.name("mpg")
> y <- as.name("wt")
>
> eval(substitute(qplot(x, y, data=mtcars), list(x=x, y=y)))
>
> Hadley
>



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 Mon 31 Mar 2008 - 07:42:23 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 Mon 31 Mar 2008 - 08:30:24 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