Hi, welcome to the forum @dlase626! So I can't answer your question directly, but here is a solution which takes your data and converts it from wide to long format which is typically prefereable for R. There are probably more elegant ways to do this though...
library(tidyverse)
data<- data.frame(
Year = c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
Population = c(878000, 879460, 958246, 911342, 933491, 938868, 938608,
946621, 950277, 954953, 960061),
Year2 = c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
Population2 = c(878000, 870380, 884095, 896338, 896338, 892257, 884688,
883457, 878678, 874893, 871292),
Year3 = c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
Population3 = c(878000, 859938, 907107, 852758, 854020, 839844, 824447,
813650, 800347, 788123, 776074),
Year4 = c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
Population4 = c(878000, 849950, 880930, 822787, 813952, 790908, 768598,
749692, 729361, 710295, 691625),
Year5 = c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
Population5 = c(878000, 840416, 855951, 794175, 776077, 745281, 716903,
691183, 665017, 640586, 616825)
)
# Convert your data to the prefered format...
long_format <-
data %>%
gather(Population, value, -Year) %>%
# Get rid of 'values' in the Population column which don't contain 'Population'
filter(grepl("Population", Population)) %>%
# Extract the population number
mutate(Population = str_extract(Population, "[0-9]+"),
# For population 1, add 1 since it's not defined in the data
Population = ifelse(is.na(Population), "1", Population))
head(long_format)
#> Year Population value
#> 1 0 1 878000
#> 2 1 1 879460
#> 3 2 1 958246
#> 4 3 1 911342
#> 5 4 1 933491
#> 6 5 1 938868
ggplot(long_format, aes(x = Year, y = value, group = Population, colour = Population)) +
geom_line(size = 1) +
theme_bw() +
scale_x_continuous(
breaks = seq(0,10,1),
name = "Year"
) +
scale_y_continuous(
name = "Population size"
)
Created on 2019-06-06 by the reprex package (v0.2.1)
Is this what you want?