💾 Archived View for gemlog.blue › users › cariboudatascience › 1613773026.gmi captured on 2023-04-26 at 14:56:26. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2021-12-04)

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

Fruit Consumption Per Capita: 1960 - 2017

Five Countries with hightest Fruit Comsumption

Software required to recreate plot:

Walkthough (R Code)

Gemini Browser

Caribou Data Science(Capsule)

Run R Code:

library(ggplot2)
library(scales)
library(dplyr)
library(tidyr)
## Import Fruit Consumption data
rm(list=ls())
fruit <- read.csv("./DATA/1-fruit-consumption-per-capita.csv")
fruit <- fruit %>%select(-Code) 
colnames(fruit) <- c("Country","Year","Fruits")
fruits_top <- fruit %>% filter(Year =="2017") %>%  top_n(5,Fruits)
fruits_top <- as.data.frame(fruits_top)

ggplot(fruits_top) +
  geom_col(aes(x=reorder(Country,Fruits),y=Fruits)) + coord_flip() +
  labs(title="Top 5 countries by per Capita Fruit Production")

countries_five <- fruits_top %>% select(Country) %>% left_join(fruit,by="Country")
head(countries_five)
tail(countries_five)

### Plot Top % Countries by Kg cosummed per year per person.
##
ggplot(countries_five) + geom_line(aes(x=Year,y=Fruits,col=Country)) +
  labs(title = "Fruit Consumption Kg/Person/Year",subtitle = "( Top 5 countries)",
       y="Fruit Consumed per person Kg")

### Plot of US Fruit consumption 

fruit %>% filter(Country =="United States") %>%
  ggplot() + geom_line(aes(x=Year,y=Fruits)) +
  labs(title="US Fruit Consumption: Kg/Year/Person (1960-2017)",
       y="Kilograms Per Person")

Plots:

Top 5 Countries

Top 5 Countries by Year

US Fruit Comsumption by Year

Part 2: Code Continues with Two More Plots:

countries_five %>% filter(Year >="2010") %>%
  ggplot() + geom_col(aes(x=Country,y=Fruits)) + 
  facet_wrap(~Year,ncol=2) + coord_flip() +
  labs(title="Fruit Consumption by Country by Year/Kg/Person")

ggplot(countries_five) + geom_line(aes(x=Year,y=Fruits,col=Country)) +
  labs(title = "Fruit Consumption Kg/Person/Year",subtitle = "( Top 5 countries)",
       y="Fruit Consumed per person Kg") + facet_wrap(~Country,scale="free_y",ncol=2) +
  geom_smooth(aes(x=Year, y= Fruits),method="lm")

Plots:

Fruit Comsumption by Country/Year

Fruit Comsumption Per Year

Part 3: Fruit Consumption by Kilograms, Type and Year


fruit_type <- read.csv("./DATA/3-fruit-consumption-by-fruit-type.csv")
colnames(fruit_type) <-c("Country","Code","Year",
                         "Apples","Bananas","Citrus",
                         "Dates","Other","Grapefruit",
                         "Grapes","Lemons","Oranges",
                         "Pineapples","Plantains")
fruit_type <- fruit_type %>% select(Country:Dates,Grapefruit:Plantains,Other)
summary(fruit_type)
fruit_type_long <- fruit_type %>% pivot_longer(cols = Apples:Other) %>%
  rename("Fruit" = "name") %>% rename("perCapita" = "value") %>% select(-Code)

### PLot of Fruit Consumption Wroldwide by Fruit Type
fruit_type_long %>% filter(Country =="World" & Fruit !="Other") %>% 
  ggplot() + geom_line(aes(x=Year,y=perCapita,col=Fruit,size=0.5)) +
  labs(title="Fruit Consumption per Person by Fruit and Year",
       caption = "(Average fruit consumption per person, differentiated by fruit types, measured in Kilograms per Year)",
       y="Kilograms per Person") + guides(color = guide_legend(override.aes = list(size = 2))) +
  scale_y_continuous(
    labels = scales::number_format(accuracy = 0.01,
                                   decimal.mark = '.')) 

Fruit Comsumption by Type and Year (per capita)

Resources:

R Code, and data

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

Download and install RStudio

Comments, Questions, Request:

https://github.com/davidjayjackson/OWID-diet-vegetable-fruit/issues