Hi,
I have to admit that don't understand how this works, but changing
subdat = subset(test, z < i*10)
gg <- ggplot(subdat, aes(x,y)) + geom_point(aes(colour =
cut(subdat$z, myseq) )) +
to
subdat = subset(test, z < i*10)
subdat$z <- cut(subdat$z, myseq)
gg <- ggplot(subdat, aes(x,y)) + geom_point(aes(colour = z)) +
works.
Best,
Ista
On Thu, Sep 27, 2012 at 10:50 AM, hainsjc <
hai...@gmail.com> wrote:
> Hi ggplot2 group,
> I am trying to make 4 plots in a loop and then put them in a png file. I can
> do this fine in the base R package just by using par(mfrow..), but this
> doesn't seem to work with ggplot2 (my lack of understanding of this is
> probably most of my problem). I found a nice example of a workaround here in
> the discussion and I tried to apply it to my project but I get the error
> message
>
> Error: Aesthetics must either be length one, or the same length as the
> dataProblems:x, y.
>
> Does anyone have any suggestions? I don't have the book, would that solve
> most of my problems?
>
> mycol = brewer.pal(5, "Spectral")
> test = data.frame(x = c(0:100), y = c(0:100), z = c(0:100))
> myseq = seq(min(test$z, na.rm = T), max(test$z, na.rm = T),
> (max(test$z, na.rm = T) - min(test$z, na.rm = T))/length(mycol))
> myplots = list()
> for (i in 1:4){
> subdat = subset(test, z < i*10)
> gg <- ggplot(subdat, aes(x,y)) + geom_point(aes(colour = cut(subdat$z,
> myseq) )) +
> scale_colour_manual(values = mycol)+
> xlim(c(0, 100)) + ylim(c(0, 100))+
> labs(x = "X", y ="Y", colour = "Z") +
> opts( title = paste("plot", i))
> myplots = c(myplots, list(gg))
> }## End of loop
>
>
>
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example:
>
https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email
ggp...@googlegroups.com
> To unsubscribe: email
ggplot2+u...@googlegroups.com
> More options:
http://groups.google.com/group/ggplot2