Create Graph By Year

Each of my pdf files are done by years "Data2007.csv", "Data2008.csv", etc.

In the CSV:

Country Region1 Region2
x        200        100
y        120        150 

I'm trying to create a graph that shows the years on the X axis, the number in the y axis and have it show each country w/ a different line for a specific region.

This is my code so far, but I'm stuck on how to create this data since all I have is each data organized by year.

  x <- read_csv(file)
  year <- str_extract(file, '\\d+')
  x[is.na(x)] = 0
  x$CITIZENSHIP <- str_to_title(x$CITIZENSHIP)
  x$Region <- countrycode(sourcevar = x$CITIZENSHIP, origin = "country.name", destination = "region")
  x[nrow(x), 26] <- "Total"
  World_Region <- ddply(x,"Region",numcolwise(sum))
  Latin_America <- x %>% filter(Region == "Latin America & Caribbean")
  South_West <- Latin_America
  South_West <- South_West %>% gather("Region", "Apprehension", 2:10)
}
filename <- list.files('Downloads/BorderData/', pattern = '\\.csv$', full.names = TRUE)
list_LA <- lapply(filename, South_West)


Read more here: https://stackoverflow.com/questions/68460261/create-graph-by-year

Content Attribution

This content was originally published by josephtg1 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: