library(ggplot2) library(scales) library(dplyr) library(tidyr) rm(list=ls()) vegetable_consumption <- read.csv("./DATA/20-vegetable-consumption-per-capita.csv") colnames(vegetable_consumption) <- c("Country","Code","Year","Vegetables") vegetable_consumption %>% filter(Country == "United States") %>% ggplot() + geom_line(aes(x=Year,y=Vegetables),lwd=2,col="red") + scale_y_continuous(labels=comma) + labs(title="United States Vegetable Consumption Per Capita by Year", subtitle = "(1961 - 2017)", y="Kilogram/Person/Year")
US Veggie Consumption Per-Capita
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) ggplot(countries_top_five) + geom_line(aes(x=Year,y=Vegetables,col=Country)) + labs(title = "Vegetables Consumption Kg/Person/Year",subtitle = "( Top 5 countries)", y="Vegetables Consumed per person Kg") ggplot(countries_top_five) + geom_col(aes(x=Year,y=Vegetables)) + facet_wrap(~Country) + labs(title="Top Five Countries by Per Capita ", subtitle = "(Vegetable Consumption per Capita)", y="Vegetables by Kg/Person/Year")