library(gapminder)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.1 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.3 ✔ tibble 3.2.1
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ purrr 1.0.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(rio)
library(plotly)
##
## Attaching package: 'plotly'
##
## The following object is masked from 'package:rio':
##
## export
##
## The following object is masked from 'package:ggplot2':
##
## last_plot
##
## The following object is masked from 'package:stats':
##
## filter
##
## The following object is masked from 'package:graphics':
##
## layout
library(countrycode)
library(ggplot2)
fruit <- read.csv("fruit_data.csv")
fruit1 <- fruit %>%
filter(Year == "2021")
fruit1 <- fruit1 %>%
rename(fruit_consumption = "Fruit...00002919....Food.available.for.consumption...0645pc....kilograms.per.year.per.capita",
gdp_per_capita = "GDP.per.capita..PPP..constant.2017.international...")
fruit1 <- fruit1 %>% drop_na(gdp_per_capita, fruit_consumption)
fruit1$Continent <- countrycode(fruit1$Entity, "country.name", "continent")
fruit1 <- fruit1 %>% drop_na(Continent)
ggplot(fruit1, aes(x = log(gdp_per_capita), y = fruit_consumption, color = Continent)) +
geom_point() +
scale_x_continuous(
breaks = log(c(1000, 2000, 5000, 10000, 20000, 50000, 100000)),
labels = c("$1,000", "$2,000", "$5,000", "$10,000", "$20,000", "$50,000", "$100,000")
) +
scale_y_continuous(
labels = function(x) paste(x, "kg")
) +
labs(x = "GDP per Capita", y = "Fruit supply per person", title = "Fruit consumption vs. GDP per capita, 2021",
subtitle = "Average per capita fruit supply, measured in kilograms per year versus gross domestic product (GDP) per capita,\nmeasured in constant international-$.",
caption = "Data source: Food and Agriculture Organization of the United Nations (2023); World Bank (2023)") +
theme_minimal()
