Graphics Reference
In-Depth Information
Figure 10-2. Left: legend on top; right: legend inside of graphing area
The legend can also be placed inside the graphing area by specifying a coordinate position, as
bottom left and goes to (1, 1) in the top right.
Discussion
You can also use
legend.justification
to set which partof the legend box is set to the pos-
ition at
legend.position
. By default, the center of the legend (.5, .5) is placed at the coordin-
ate, but it is often useful to specify a different point.
For example, this will place the bottom-right corner of the legend (1,0) in the bottom-right corner
of the graphing area (1,0):
p
+
theme(legend.position
=
c(
1
,
0
), legend.justification
=
c(
1
,
0
))