Me gustaría expresar las leyendas en español, ejemplo Brazil como Brasil. Esto se puede hacer modificando el dataset pero creo que debe haber una forma más rápida en ggplot. Mi script es el siguiente
library(tidyr)
library(tidyverse)
library(panelr)
library(dplyr)
library(ggplot2)
library(readxl)
data <- read_excel("2021-FKRSU-Update-12-08-2021.xlsx")
View(data)
attach(data)
# Armar Panel
data_panel <- panel_data(data, id = code_ifs, wave = year)
# Ahora agrupamos por region y mundial
avgregion <- data %>%
group_by(year, region) %>%
summarize(ka_avg = mean(ka, na.rm=TRUE),
kao_avg = mean(kao, na.rm=TRUE))
avgworld <- data %>%
group_by(year) %>%
summarize(ka_avg = mean(ka, na.rm=TRUE),
kao_avg = mean(kao, na.rm=TRUE))
avgworld$region <- "world"
paises <- data.frame(data$year, data$country, data$ka, data$kao)
colnames(paises) <- c("year", "region", "ka_avg", "kao_avg")
# Armo el data set para plot
dataset <- bind_rows(avgregion, avgworld, paises)
# Plot
dataset %>%
ggplot(aes(x=year,y=ka_avg, group=region))+
geom_line(colour="grey", alpha=.4)+
geom_line(aes(x=year,y=ka_avg, color=region),
data = dataset %>% filter(grepl("Chile|Brazil|Peru|Colombia|Argentina|world|Latin America & Caribbean",
region)), size=1, show.legend = T)+
geom_text(aes(x=year+.3,y=ka_avg, label=region),
data = dataset %>% filter(grepl("Chile|Brazil|Peru|Colombia|Argentina|world|Latin America & Caribbean",
region),year==2020))+
theme_classic()+
ggtitle("Control de capitales")+
xlab("")+
ylab("")+
theme(axis.line.x.bottom=element_line(size=1, colour = "grey"),
axis.text.x=element_text(size=10),
axis.text.y = element_text(size=10),
axis.line.y.left = element_line(size=1, colour = "grey"),
legend.title = element_blank())