You can add individual frequencies per category. To do this, use the geom_text()
function and simply add it to the last plot: The first argument indicates that the frequencies are used here, and in the second argument, you specify that the output should be the counted frequency (label = ..count..`):
barplotBeyonce +
geom_text(
stat = "count",
aes(label = ..count..)
)
## Warning: The dot-dot notation (`..count..`) was deprecated in ggplot2 3.4.0.
## ℹ Please use `after_stat(count)` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
Now, some of the numbers may not be readable. Let’s move the number values and change the font color! We can adjust the position and appearance using various arguments within geom_text()
:
barplotBeyonce +
geom_text(
stat = "count",
aes(label = ..count..),
vjust = 1.5,
color = "white"
)
Modify the code above so that the numbers are above the bars and the font color is darkblue
! Try it out a bit before looking at the solution!
barplotBeyonce +
geom_text(
stat = “count”,
aes(label = ..count..),
vjust = -0.5,
color = “darkblue”
)
You can adjust the size of the text using the size
argument. Just change the values in the code to see how it changes!
barplotBeyonce +
geom_text(
stat = "count",
aes(label = ..count..),
vjust = 1.5,
size = 8,
color = "white"
)
Let’s move on to the final settings!