@@ -968,14 +968,17 @@ by setting `.desc = TRUE`.
968
968
We do this here so that the largest bar will be closest to the axis line,
969
969
which is more visually appealing.
970
970
971
- To label the x and y axes, we will use the ` labs ` function
972
- instead of the ` xlab ` and ` ylab ` functions from earlier in this chapter.
973
- The ` labs ` function is more general; we are using it in this case because
974
- we would also like to change the legend label.
975
- The default label is the name of the column being mapped to ` fill ` . Here that
976
- would be ` landmass_type ` ;
977
- however ` landmass_type ` is not proper English (and so is less readable).
978
- Thus we use the ` fill ` argument inside ` labs ` to change that to "Type."
971
+ To finalize this plot we will customize the axis and legend labels,
972
+ and add a title to the chart. Plot titles are not always required, especially when
973
+ it would be redundant with an already-existing
974
+ caption or surrounding context (e.g., in a slide presentation with annotations).
975
+ But if you decide to include one, a good plot title should provide the take home message
976
+ that you want readers to focus on, e.g., "The Earth's seven largest landmasses are all continents,"
977
+ or a more general summary of the information displayed, e.g., "The twelve largest landmasses on Earth."
978
+
979
+ To make these final adjustments we will use the ` labs ` function rather than the ` xlab ` and ` ylab ` functions
980
+ we have seen earlier in this chapter, as ` labs ` lets us modify the legend label and title in addition to axis labels.
981
+ We provide a label for each aesthetic mapping in the plot&mdash ; in this case, ` x ` , ` y ` , and ` fill ` &mdash ; as well as one for the ` title ` argument.
979
982
Finally, we again \index{ggplot!reorder} use the ` theme ` function
980
983
to change the font size.
981
984
@@ -985,7 +988,10 @@ islands_bar <- ggplot(islands_top12,
985
988
y = fct_reorder(landmass, size, .desc = TRUE),
986
989
fill = landmass_type)) +
987
990
geom_bar(stat = "identity") +
988
- labs(x = "Size (1000 square mi)", y = "Landmass", fill = "Type") +
991
+ labs(x = "Size (1000 square mi)",
992
+ y = "Landmass",
993
+ fill = "Type",
994
+ title = "The Earth's seven largest landmasses are all continents") +
989
995
theme(text = element_text(size = 12))
990
996
991
997
islands_bar
0 commit comments