Graphics Reference
In-Depth Information
Figure 4-25. A line graph with a shaded confidence region
The shaded region is actually a very dark grey, but it is mostly transparent. The transparency is
set with
alpha=0.2
, which makes it 80% transparent.
Discussion
Notice that the
geom_ribbon()
is before
geom_line()
, so that the line is drawn on top of the
shaded region. If the reverse order were used, the shaded region could obscure the line. In this
particular case that wouldn't be a problem since the shaded region is mostly transparent, but it
would be a problem if the shaded region were opaque.
Instead of a shaded region, you can also use dotted lines to represent the upper and lower bounds
(
Figure 4-26
)
:
# With a dotted line for upper and lower bounds
ggplot(clim, aes(x
=
Year, y
=
Anomaly10y))
+
geom_line(aes(y
=
Anomaly10y
-
Unc10y), colour
=
"grey50"
, linetype
=
"dotted"
)
+
geom_line(aes(y
=
Anomaly10y
+
Unc10y), colour
=
"grey50"
, linetype
=
"dotted"
)
+
geom_line()