Changing aesthetic mappings.

4 views
Skip to first unread message

Jim Watkins

unread,
May 31, 2009, 8:43:46 AM5/31/09
to ggp...@googlegroups.com
On p. 47 of the current ggplot draft, examples are provided regarding
changing aesthetic mappings. The following sequence of R code is provided:

p <- ggplot(mtcars, aes(x = mpg, y = wt))
p + geom_point()
p + geom_point(aes(colour = factor(cyl)))
p + geom_point(aes(y = disp))

I don't understand the plot generated by the last of these statements
(displayed on the right side on p. 48).

1. The marginal of the scatterplot indicates that y has been correctly
remapped to disp, so why is the y axis still labeled wt?
2. The colour mapping for factor(cyl) was not explicitly overridden, so why
isn't this mapping still in effect in the plot?


s...@z107.de

unread,
May 31, 2009, 9:20:19 AM5/31/09
to Jim Watkins, ggp...@googlegroups.com
hello,

On Sun, May 31, 2009 at 08:43:46AM -0400, Jim Watkins wrote:
>
> On p. 47 of the current ggplot draft, examples are provided regarding
> changing aesthetic mappings. The following sequence of R code is provided:
>
> p <- ggplot(mtcars, aes(x = mpg, y = wt))
> p + geom_point()
> p + geom_point(aes(colour = factor(cyl)))
> p + geom_point(aes(y = disp))
>
> I don't understand the plot generated by the last of these statements
> (displayed on the right side on p. 48).
>
> 1. The marginal of the scatterplot indicates that y has been correctly
> remapped to disp, so why is the y axis still labeled wt?

It's written on the same page:

| Aesthetic mappings specified in a layer
| act _nly that layer. For that reason, unless you modify the default
| scales, axis labels and legend titles will be based on the plot defaults.

and the default was set with ggplot(mtcars, aes(x = mpg, y = wt)).


> 2. The colour mapping for factor(cyl) was not explicitly overridden, so why
> isn't this mapping still in effect in the plot?

because the mapping is not written to p. What you are thinking of is:

p <- p + geom_point(aes(colour = factor(cyl)))


p + geom_point(aes(y = disp))


regards,
stefan

Reply all
Reply to author
Forward
0 new messages