Data Science Desktop Survival Guide
by Graham Williams |
|||||
Bar Chart Supplied Values |
20200427
ds %>%
count(wind_dir_9am) %>% ggplot(aes(x=wind_dir_9am, y=n)) + geom_col() + scale_y_continuous(labels=comma) + labs(x=vnames["wind_dir_9am"], y="Count")
If the values of the bars are supplied in the source dataset (the y-axis) ggplot2::geom_col() is used. In this example we manually count the frequency of each wind direction in the dataset prior to invoking ggplot2::ggplot(). This modified dataset is then passed on to ggplot2::ggplot() to display. Of course, it would be better in this specific example to let ggplot2::geom_bar() do the work itself as in Section 10.8.
|