Graphics Reference
In-Depth Information
Figure 10-3. Left: legend in bottom-right corner; right: legend in top-right corner.
And this will place the top-right corner of the legend in the top-right corner of the graphing area,
as in the graph on the right in
Figure 10-3
:
p
+
theme(legend.position
=
c(
1
,
1
), legend.justification
=
c(
1
,
1
))
When placing the legend inside of the graphing area, it may be helpful to add an opaque border
to set it apart (
Figure 10-4
, left):
p
+
theme(legend.position
=
c(
.85
,
.2
))
+
theme(legend.background
=
element_rect(fill
=
"white"
, colour
=
"black"
))