ggplot2 lets you save reusable code chunks as R objects. To add to
Brandon's comments:
#--------
plot0 <- ggplot(data=CO2, aes(x=conc, y=uptake )) + geom_point()
plot0 <- scale_y_continuous(limits=c(0,100), breaks=seq(0,100,10))
plot0
#-------
failed because you replaced a ggplot object in the first line with a
ggplot2 code segment in the second. When you call plot0, you get the
print method associated with the code chunk. It is not an object of
class "gg" and "ggplot" (see below).
#------
plot1 <- ggplot(df, aes(x=runif(100), y=1:100)) + geom_point()
plot1 <- plot1 + scale_y_continuous(limits=c(0,100), breaks=seq(0,100,10))
plot1
#------
works because you added a chunk of ggplot2 code to an existing ggplot
object, which adds to the ggplot object.
You can combine the two with
#------
library(ggplot2)
data(CO2)
plot0 <- ggplot(data=CO2, aes(x=conc, y=uptake )) + geom_point()
plot1 <- scale_y_continuous(limits=c(0,100), breaks=seq(0,100,10))
plot0 + plot1
#------
This saves the second ggplot2 code chunk as a separate object (which
you did the first time) and adds it to the existing plot0 object in
the last line. To see the distinction among the three objects created
above,
> class(plot1)
[1] "ScaleContinuousPosition" "ScaleContinuous"
[3] "Scale" "ggproto"
> class(plot0)
[1] "gg" "ggplot"
> class(plot0 + plot1)
[1] "gg" "ggplot"
Dennis
> --
> --
> 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
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ggplot2" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
ggplot2+u...@googlegroups.com.
> For more options, visit
https://groups.google.com/d/optout.