💾 Archived View for gemlog.blue › users › cariboudatascience › 1614374507.gmi captured on 2023-06-14 at 15:49:16. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2021-12-04)

-=-=-=-=-=-=-

Worldwide/United States : Vegetable Consumption Per Capita (1961 - 2013) [Part 3/4]

Our World In Data

Software required to recreate plot:

US Vegetable Consumption per Capita in Kilograms

Calculate and plot average per capita consumption by Year

library(ggplot2)
library(scales)
library(tidyr)
library(dplyr)

vegetable_consumption <- read.csv("./DATA/20-vegetable-consumption-per-capita.csv")
colnames(vegetable_consumption) <- c("Country","Code","Year","Vegetables")

veggie_average <- vegetable_consumption %>% group_by(Year) %>%
  summarise(Average = mean(Vegetables),
            Median = median(median(Vegetables)),
            Maximum = max(Vegetables))

Plot One

veggie_average <- as.data.frame(veggie_average)
  ggplot(veggie_average) + geom_line(aes(x=Year,y=Average,col="Average")) +
  geom_line(aes(x=Year,y=Median,col="Median")) +
    geom_line(aes(x=Year,y=Maximum,col="Maximum")) +
    scale_y_log10() + labs(title="Vegetable Consumtion Per Capita(Plot One)",
                           y="Mean/Median/Maximum")
  

### Bottom Five Countries with highest per cap consumption

    vegie_top <- vegetable_consumption %>% filter(Year =="2017") %>%  top_n(-5,Vegetables)
  vegie_top <- as.data.frame(vegie_top)
  
  countries_top_five <- vegie_top %>% select(Country) %>% left_join(vegetable_consumption,by="Country")
  head(countries_top_five)
  tail(countries_top_five)

Plot Two

  ggplot(countries_top_five) + geom_line(aes(x=Year,y=Vegetables,col=Country)) +
    labs(title = "Vegetables Consumption Kg/Person/Year (Plot Two)",subtitle = "(Bottom 5 countries)",
         y="Vegetables Consumed per person Kg")

Plot Three

  ggplot(countries_top_five) + geom_col(aes(x=Year,y=Vegetables)) +
    facet_wrap(~Country,ncol=2,scale="free_y") + labs(title="Bottom Five Countries by Per Capita (Plot 3) ",
                                subtitle = "(Vegetable Consumption per Capita)",
                                y="Vegetables by Kg/Person/Year") +
    geom_line(data=veggie_average,aes(x=Year,y=Average,col="Mean"))

Plots of Bottom Five Countries Per Capita Per Year

Plot One

Plot Two

Plot Three

Resources:

R Code, and data

R Language and Rtools40 (click and "base" and "Rtools")

Download and install RStudio

Comments, Question and Request