Graphics Reference
In-Depth Information
hw
<-
ggplot(heightweight, aes(x
=
ageYear, y
=
heightIn, colour
=
sex))
+
geom_point(aes(size
=
weightLb))
+
scale_size_continuous(range
=
c(
1
,
4
))
hw
# With new legend titles
hw
+
labs(colour
=
"Male/Female"
, size
=
"Weight\n(pounds)"
)
Figure 10-9. Left: two legends with original titles; right: with new titles
If you have one variable mapped to two separate aesthetics, the default is to have a single legend
that combines both. For example, if we map
sex
to both
shape
and
weight
, there will be just
one legend (
Figure 10-10
, left):
hw1
<-
ggplot(heightweight, aes(x
=
ageYear, y
=
heightIn, shape
=
sex, colour
=
sex))
+
geom_point()
hw1