Last active
November 25, 2019 19:53
-
-
Save jmcastagnetto/7a2c11fbbc56152fda8a90eb2dedd9d9 to your computer and use it in GitHub Desktop.
Plot of the SFS index for South America
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(countrycode) | |
library(tidyverse) | |
library(ggrepel) | |
df <- readxl::read_excel("Sustainable_food_systems_global_index-1.xlsx", sheet = 1, skip = 5) | |
df <- df %>% | |
mutate( | |
region = countrycode(origin = "iso3c", | |
sourcevar = ISO3, | |
destination = "region") | |
) %>% | |
mutate_at( | |
3:8, | |
as.numeric | |
) %>% | |
pivot_longer( | |
cols = 3:8, | |
names_to = "period", | |
values_to = "sfs" | |
) %>% | |
mutate( | |
period = str_remove(string = period, pattern = "SFS index ") | |
) | |
sa <- df %>% | |
filter( | |
region == "South America" | |
) | |
sa_avg <- sa %>% | |
group_by(region, period) %>% | |
summarise( | |
sfs = mean(sfs) | |
) %>% | |
mutate( | |
Country = region, | |
ISO3 = "" | |
) %>% | |
select( | |
Country, ISO3, region, period, sfs | |
) | |
sa <- bind_rows(sa, sa_avg) | |
ggplot(sa, aes(x = period, y = sfs, color = Country, group = Country)) + | |
geom_point(show.legend = FALSE) + | |
geom_line(show.legend = FALSE) + | |
geom_label_repel( | |
data = sa %>% filter(period == "2000-2003"), | |
aes(label = Country, x = period, y = sfs, color = Country), | |
hjust = 1, show.legend = FALSE, nudge_x = -.1 | |
) + | |
ylim(0.4, .65) + | |
labs( | |
y = "SFS Index", | |
x = "Period", | |
title = "Sustainable Food Systems Index -- South America", | |
subtitle = "Source: hhttps://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/GYEG59" | |
caption = "2019-11-25 // @jmcastagnetto, Jesus M. Castagnetto" | |
) + | |
scale_color_discrete() + | |
theme_bw(16) |
Author
jmcastagnetto
commented
Nov 25, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment