Load Data
library(fivethirtyeight)
## Warning: package 'fivethirtyeight' was built under R version 4.2.2
## Some larger datasets need to be installed separately, like senators and
## house_district_forecast. To install these, we recommend you install the
## fivethirtyeightdata package by running:
## install.packages('fivethirtyeightdata', repos =
## 'https://fivethirtyeightdata.github.io/drat/', type = 'source')
library(tidyverse)
## ── Attaching packages
## ───────────────────────────────────────
## tidyverse 1.3.2 ──
## ✔ ggplot2 3.3.6 ✔ purrr 0.3.4
## ✔ tibble 3.1.8 ✔ dplyr 1.0.10
## ✔ tidyr 1.2.1 ✔ stringr 1.4.1
## ✔ readr 2.1.2 ✔ forcats 0.5.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
library(ggplot2)
library(knitr)
library(tidyr)
drinks <- read.csv("drinks.csv", header = TRUE) %>% filter(country %in% c("USA", "Seychelles", "Iceland", "Greece")) %>% rename(beer=beer_servings, spirit=spirit_servings, wine=wine_servings, total=total_litres_of_pure_alcohol)
kable(drinks)
| Greece |
133 |
112 |
218 |
8.3 |
| Iceland |
233 |
61 |
78 |
6.6 |
| Seychelles |
157 |
25 |
51 |
4.1 |
| USA |
249 |
158 |
84 |
8.7 |
drinks2 <- gather(drinks, key = type, value = "servings", -c(country, total))
ggplot(drinks2, aes(country, servings, fill = type)) + geom_bar(stat = "identity", position = "dodge") + coord_flip()
