On 7/12/07, hadley wickham <[EMAIL PROTECTED]> wrote:
> Hi Steve,
>
> You need to explicitly print the ggplot object:
> ggplot(mydata, aes(x=mydata$varc)) + geom_bar()
>
> (this is a R-faq for lattice plots, and ggplot works the same way)
>
> In the latest version of ggplot (0.5.4) you can construct the plot
> before hand and modify the aesthetics in each instance of the loop:
>
> p <- ggplot(mydata) + geom_bar()
> mydata$varc = c(1,2,3)
> for (i in 1:1){
>         jpeg("test3.jpg")
>         p + aes(x = mydata$varc)
>         dev.off()
> }
>
> (not that this will actually work because you're not using i inside
> your loop anywhere)
>
> (and to be strictly correct you should probably use list(x =
> as.name(names(mydata)[i]))  instead of the aes call - but I haven't
> written any documentation for this yet)

Actually a better solution (will be included in the next version of ggplot) is:

aes_string <- function(...) structure(lapply(list(...), as.name),
class="uneval")

p + aes_string(x = names(mydata)[i])

It converts aes(x = "x", y="y") to aes(x=x, y=y).  The first is easy
to generate programmatically, the second is less to type.

Hadley

______________________________________________
[email protected] 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