[R] scaling of different data sets in ggplot

Stephen Tucker brown_emu at yahoo.com
Sat Jul 14 23:48:18 CEST 2007


Dear list (but probably mostly Hadley):

In ggplot, operations to modify 'guides' are accessed through grid
objects, but I did not find mention of creating new guides or possibly
removing them altogether using ggplot functions. I wonder if this is
something I need to learn grid to learn more about (which I hope to do
eventually).

Also, ggplot()+geom_object() [where 'object' can be point, line, etc.]
or layer() contains specification for the data, mappings and
geoms/stats - but the geoms/stats can be scale-dependent [for
instance, log]. so I wonder how different scalings can be applied to
different data sets.

Below is an example that requires both:

x <- runif(100) y <- exp(x^2) z <- x^2+rnorm(100,0,0.02)

par(mar=c(5,4,2,4)+0.1) plot(x,y,log="y") lines(lowess(x,y,f=1/3))
par(new=TRUE) plot(x,z,col=2,pch=3,yaxt="n",ylab="")
lines(lowess(x,z,f=1/3),col=2) axis(4,col=2,col.axis=2)
mtext("z",4,line=3,col=2)

In ggplot:

## data specification
ggplot(data=data.frame(x,y,z)) +

  ## first set of points geom_point(mapping=aes(x=x,y=y)) +
  ## scale_y_log() +

  ## second set of points geom_point(mapping=aes(x=x,y=z),pch=3) +
  ## layer(mapping=aes(x=x,y=z),stat="smooth",method="loess") +
  ## scale_y_continuous()

scale_y_log() and scale_y_continuous() appear to apply to both mappings at
once, and I can't figure out how to associate them with the intended ones (I
expect this will be a desire for size and color scales as well).

Of course, I can always try to fool the system by (1) applying the scaling a
priori to create a new variable, (2) plotting points from the new variable,
and (3) creating a new axis with custom labels. Which then brings me back to
...how to add new guides? :)

Thanks,

Stephen



      ____________________________________________________________________________________



More information about the R-help mailing list