Working with geom_col
In ggplot, there are two different ways to make bar plots: geom_col()
and geom_bar()
.
If your data is in the form where the height of the bar is encoded in a column that you want to map to the y-axis, like counts of diseases are in our data, you want to use the geom_col()
option.
Let's make a barplot of the number of cases recorded by disease for India in 1980 using geom_col()
.
This exercise is part of the course
Visualization Best Practices in R
Exercise instructions
filter()
the data to thecountry
ofIndia
and the year1980
withcountry == "India", year == 1980
.- Map
disease
to the x-axis andcases
to the y-axis in theaes()
call. - Add a
geom_col()
geometry.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
who_disease %>%
# filter to india in 1980
filter(___) %>%
# map x aesthetic to disease and y to cases
ggplot(aes(___)) +
# use geom_col to draw
___