-- Leo's gemini proxy

-- Connecting to gemlog.blue:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini

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

Countries shown in blue have an average per capita intake below 250g per person per day; countries in green are greater than 250g. National and World Health Organization (WHO) recommendations tend to range between 200-250g per day.


Our World In Data


Software required to recreate plot:

Install: R language, RTools40 and RStudio (see link below)

Packages: GGPLot2, dplyr, janitor.

Download code and data from Github.com (see link below).

Move R code and data to working directory


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


-- Response ended

-- Page fetched on Fri Apr 26 19:58:55 2024