Plots Part 2
Your humanoid robot editor J-327D takes a look at your chart and nods his head up and down, and then shakes it side to side. Things rattle inside, but you try not to notice.
“You have a good start to a chart here, but it could be mo betta.”
– J-327D, Galactic News Hub editor
A plot as an object
J-327D points out a cool thing about ggplot is your can save your plot into an object, and then keep adding layers onto that basic plot using the +
operator.
He shows you how you can do this …
Plotting values as text labels
J-327D first suggestion to improve the chart is to add the count of each species onto each bar so it is easier to read.
Use a geom to plot the count_species
on top of each bar as text.
Note there are some adjustments in the code already for the location and color of the text.
species_plot +
geom_text(
aes(label = count_species),
hjust = 1.75,
color = "white"
)
+
species_plot geom_text(
aes(label = count_species),
hjust = 1.75,
color = "white"
)
J-327D says it is interesting that you can plot a value onto a chart using geom_text()
. He noted an important thing to know is since you are pulling the value from the data you have to use aes()
to captue the data point to plot it as a label.
On to the next step
You’re the hope the galaxy needs!
Once you’ve completed the exercises above, move to the next part of this trial.