Skip to content

Commit bbb06c9

Browse files
added barplot title
1 parent dadd05b commit bbb06c9

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

source/viz.Rmd

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -968,14 +968,17 @@ by setting `.desc = TRUE`.
968968
We do this here so that the largest bar will be closest to the axis line,
969969
which is more visually appealing.
970970

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—in this case, `x`, `y`, and `fill`—as well as one for the `title` argument.
979982
Finally, we again \index{ggplot!reorder} use the `theme` function
980983
to change the font size.
981984

@@ -985,7 +988,10 @@ islands_bar <- ggplot(islands_top12,
985988
y = fct_reorder(landmass, size, .desc = TRUE),
986989
fill = landmass_type)) +
987990
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") +
989995
theme(text = element_text(size = 12))
990996
991997
islands_bar

0 commit comments

Comments
 (0)