No Visualization

Hi, can anybody help me to visualize my data. I used this code: "ggplot(filtered_data, aes(x=date, y=value, color=country))+ geom_line()+ labs(x= "Year", y= "Age dependency ratio") + theme_minimal()"

"filtered_data" is the dataframe
the dataframe represents the age dependent ration in three countries during the years 1960-2020

i want to visualize all three countries in one plot

but if I put the code in the console, I get this error code: geom_line()`: Each group consists of only
one observation.
:information_source: Do you need to adjust the group aesthetic?

what's my mistake?

here's the data frame:

iso3c date value indicatorID
5491 CHN 2020 44.14078 SP.POP.DPND
5492 CHN 2019 43.43833 SP.POP.DPND
5493 CHN 2018 42.59356 SP.POP.DPND
5494 CHN 2017 41.54489 SP.POP.DPND
5495 CHN 2016 40.45790 SP.POP.DPND
5496 CHN 2015 39.61922 SP.POP.DPND
5497 CHN 2014 38.87740 SP.POP.DPND
5498 CHN 2013 38.21255 SP.POP.DPND
5499 CHN 2012 37.65673 SP.POP.DPND
5500 CHN 2011 37.27427 SP.POP.DPND
5501 CHN 2010 37.11989 SP.POP.DPND
5502 CHN 2009 37.10396 SP.POP.DPND
5503 CHN 2008 37.22402 SP.POP.DPND
5504 CHN 2007 37.51349 SP.POP.DPND
5505 CHN 2006 38.00776 SP.POP.DPND
5506 CHN 2005 39.03199 SP.POP.DPND
5507 CHN 2004 40.46390 SP.POP.DPND
5508 CHN 2003 41.84223 SP.POP.DPND
5509 CHN 2002 43.28138 SP.POP.DPND
5510 CHN 2001 44.72739 SP.POP.DPND
5511 CHN 2000 45.88856 SP.POP.DPND
5512 CHN 1999 46.83161 SP.POP.DPND
5513 CHN 1998 47.63393 SP.POP.DPND
5514 CHN 1997 48.58040 SP.POP.DPND
5515 CHN 1996 49.63936 SP.POP.DPND
5516 CHN 1995 50.42039 SP.POP.DPND
5517 CHN 1994 51.00996 SP.POP.DPND
5518 CHN 1993 51.39484 SP.POP.DPND
5519 CHN 1992 51.60333 SP.POP.DPND
5520 CHN 1991 51.86290 SP.POP.DPND
5521 CHN 1990 51.93035 SP.POP.DPND
5522 CHN 1989 52.00635 SP.POP.DPND
5523 CHN 1988 52.64234 SP.POP.DPND
5524 CHN 1987 53.58567 SP.POP.DPND
5525 CHN 1986 54.79317 SP.POP.DPND
5526 CHN 1985 56.57888 SP.POP.DPND
5527 CHN 1984 58.80795 SP.POP.DPND
5528 CHN 1983 61.37641 SP.POP.DPND
5529 CHN 1982 63.58034 SP.POP.DPND
5530 CHN 1981 65.52561 SP.POP.DPND
5531 CHN 1980 68.10964 SP.POP.DPND
5532 CHN 1979 71.05709 SP.POP.DPND
5533 CHN 1978 74.76929 SP.POP.DPND
5534 CHN 1977 78.43501 SP.POP.DPND
5535 CHN 1976 79.76282 SP.POP.DPND
5536 CHN 1975 79.50648 SP.POP.DPND
5537 CHN 1974 79.06412 SP.POP.DPND
5538 CHN 1973 78.83124 SP.POP.DPND
5539 CHN 1972 79.48118 SP.POP.DPND
5540 CHN 1971 80.18821 SP.POP.DPND
5541 CHN 1970 80.52403 SP.POP.DPND
5542 CHN 1969 80.96198 SP.POP.DPND
5543 CHN 1968 81.16693 SP.POP.DPND
5544 CHN 1967 81.78308 SP.POP.DPND
5545 CHN 1966 82.41039 SP.POP.DPND
5546 CHN 1965 82.23168 SP.POP.DPND
5547 CHN 1964 81.57570 SP.POP.DPND
5548 CHN 1963 79.88140 SP.POP.DPND
5549 CHN 1962 78.05306 SP.POP.DPND
5550 CHN 1961 78.15700 SP.POP.DPND
5551 CHN 1960 79.57177 SP.POP.DPND
7443 DEU 2020 55.55797 SP.POP.DPND
7444 DEU 2019 54.72518 SP.POP.DPND
7445 DEU 2018 53.89533 SP.POP.DPND
7446 DEU 2017 53.14418 SP.POP.DPND
7447 DEU 2016 52.45135 SP.POP.DPND
7448 DEU 2015 51.87215 SP.POP.DPND
7449 DEU 2014 51.41220 SP.POP.DPND
7450 DEU 2013 51.13718 SP.POP.DPND
7451 DEU 2012 51.11023 SP.POP.DPND
7452 DEU 2011 51.27708 SP.POP.DPND
7453 DEU 2010 51.63420 SP.POP.DPND
7454 DEU 2009 51.75955 SP.POP.DPND
7455 DEU 2008 51.54632 SP.POP.DPND
7456 DEU 2007 51.32468 SP.POP.DPND
7457 DEU 2006 50.86981 SP.POP.DPND
7458 DEU 2005 50.13875 SP.POP.DPND
7459 DEU 2004 49.36337 SP.POP.DPND
7460 DEU 2003 48.69708 SP.POP.DPND
7461 DEU 2002 48.19626 SP.POP.DPND
7462 DEU 2001 47.70021 SP.POP.DPND
7463 DEU 2000 47.14557 SP.POP.DPND
7464 DEU 1999 46.63790 SP.POP.DPND
7465 DEU 1998 46.43077 SP.POP.DPND
7466 DEU 1997 46.45227 SP.POP.DPND
7467 DEU 1996 46.46962 SP.POP.DPND
7468 DEU 1995 46.42054 SP.POP.DPND
7469 DEU 1994 46.26455 SP.POP.DPND
7470 DEU 1993 46.00459 SP.POP.DPND
7471 DEU 1992 45.71205 SP.POP.DPND
7472 DEU 1991 45.41908 SP.POP.DPND
7473 DEU 1990 45.01678 SP.POP.DPND
7474 DEU 1989 44.59761 SP.POP.DPND
7475 DEU 1988 44.26378 SP.POP.DPND
7476 DEU 1987 44.01034 SP.POP.DPND
7477 DEU 1986 43.92813 SP.POP.DPND
7478 DEU 1985 44.03938 SP.POP.DPND
7479 DEU 1984 44.60820 SP.POP.DPND
7480 DEU 1983 45.96941 SP.POP.DPND
7481 DEU 1982 47.84619 SP.POP.DPND
7482 DEU 1981 49.84009 SP.POP.DPND
7483 DEU 1980 51.65982 SP.POP.DPND
7484 DEU 1979 53.06986 SP.POP.DPND
7485 DEU 1978 54.23803 SP.POP.DPND
7486 DEU 1977 55.27684 SP.POP.DPND
7487 DEU 1976 56.28798 SP.POP.DPND
7488 DEU 1975 57.28409 SP.POP.DPND
7489 DEU 1974 58.05290 SP.POP.DPND
7490 DEU 1973 58.57428 SP.POP.DPND
7491 DEU 1972 58.85722 SP.POP.DPND
7492 DEU 1971 58.86063 SP.POP.DPND
7493 DEU 1970 58.61768 SP.POP.DPND
7494 DEU 1969 58.17303 SP.POP.DPND
7495 DEU 1968 57.56319 SP.POP.DPND
7496 DEU 1967 56.72721 SP.POP.DPND
7497 DEU 1966 55.69675 SP.POP.DPND
7498 DEU 1965 54.66550 SP.POP.DPND
7499 DEU 1964 53.60663 SP.POP.DPND
7500 DEU 1963 52.43400 SP.POP.DPND
7501 DEU 1962 51.20971 SP.POP.DPND
7502 DEU 1961 49.85039 SP.POP.DPND
7503 DEU 1960 48.33786 SP.POP.DPND
11774 NGA 2020 86.93132 SP.POP.DPND
11775 NGA 2019 87.68050 SP.POP.DPND
11776 NGA 2018 88.33485 SP.POP.DPND
11777 NGA 2017 88.96855 SP.POP.DPND
11778 NGA 2016 89.51834 SP.POP.DPND
11779 NGA 2015 89.89683 SP.POP.DPND
11780 NGA 2014 90.15230 SP.POP.DPND
11781 NGA 2013 90.27969 SP.POP.DPND
11782 NGA 2012 90.25185 SP.POP.DPND
11783 NGA 2011 90.12990 SP.POP.DPND
11784 NGA 2010 89.94406 SP.POP.DPND
11785 NGA 2009 89.67433 SP.POP.DPND
11786 NGA 2008 89.31655 SP.POP.DPND
11787 NGA 2007 88.92249 SP.POP.DPND
11788 NGA 2006 88.51555 SP.POP.DPND
11789 NGA 2005 88.10125 SP.POP.DPND
11790 NGA 2004 87.74206 SP.POP.DPND
11791 NGA 2003 87.41564 SP.POP.DPND
11792 NGA 2002 87.11064 SP.POP.DPND
11793 NGA 2001 86.91983 SP.POP.DPND

Do you have a column named "country"?

there is no column named country

if there is no column named country in the datset, map color to iso3c

ggplot(filtered_data, aes(x = date, y = value, color = iso3c))+ 
  geom_line()+ 
  labs(x =  "Year", y =  "Age dependency ratio") + 
  theme_minimal()

unfortunately it still doesn’t work

@mduvekot's code should work. Why don't you post your code here, between sets of three backticks so it's easy to read.

Thanks, I took the data that was provided, turned it into a dataframe and made sure it does work. Here's the whole thing:

library (ggplot2)

filtered_data <- data.frame(
  iso3c = c("CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "CHN", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "NGA", "NGA", "NGA", "NGA", "NGA", "NGA", "NGA", "NGA", "NGA", "NGA", "NGA", "NGA", "NGA", "NGA", "NGA", "NGA", "NGA", "NGA", "NGA", "NGA"),
  date = c(2020, 2019, 2018, 2017, 2016, 2015, 2014, 2013, 2012, 2011, 2010, 2009, 2008, 2007, 2006, 2005, 2004, 2003, 2002, 2001, 2000, 1999, 1998, 1997, 1996, 1995, 1994, 1993, 1992, 1991, 1990, 1989, 1988, 1987, 1986, 1985, 1984, 1983, 1982, 1981, 1980, 1979, 1978, 1977, 1976, 1975, 1974, 1973, 1972, 1971, 1970, 1969, 1968, 1967, 1966, 1965, 1964, 1963, 1962, 1961, 1960, 2020, 2019, 2018, 2017, 2016, 2015, 2014, 2013, 2012, 2011, 2010, 2009, 2008, 2007, 2006, 2005, 2004, 2003, 2002, 2001, 2000, 1999, 1998, 1997, 1996, 1995, 1994, 1993, 1992, 1991, 1990, 1989, 1988, 1987, 1986, 1985, 1984, 1983, 1982, 1981, 1980, 1979, 1978, 1977, 1976, 1975, 1974, 1973, 1972, 1971, 1970, 1969, 1968, 1967, 1966, 1965, 1964, 1963, 1962, 1961, 1960, 2020, 2019, 2018, 2017, 2016, 2015, 2014, 2013, 2012, 2011, 2010, 2009, 2008, 2007, 2006, 2005, 2004, 2003, 2002, 2001),
  value = c(44.14078, 43.43833, 42.59356, 41.54489, 40.4579, 39.61922, 38.8774, 38.21255, 37.65673, 37.27427, 37.11989, 37.10396, 37.22402, 37.51349, 38.00776, 39.03199, 40.4639, 41.84223, 43.28138, 44.72739, 45.88856, 46.83161, 47.63393, 48.5804, 49.63936, 50.42039, 51.00996, 51.39484, 51.60333, 51.8629, 51.93035, 52.00635, 52.64234, 53.58567, 54.79317, 56.57888, 58.80795, 61.37641, 63.58034, 65.52561, 68.10964, 71.05709, 74.76929, 78.43501, 79.76282, 79.50648, 79.06412, 78.83124, 79.48118, 80.18821, 80.52403, 80.96198, 81.16693, 81.78308, 82.41039, 82.23168, 81.5757, 79.8814, 78.05306, 78.157, 79.57177, 55.55797, 54.72518, 53.89533, 53.14418, 52.45135, 51.87215, 51.4122, 51.13718, 51.11023, 51.27708, 51.6342, 51.75955, 51.54632, 51.32468, 50.86981, 50.13875, 49.36337, 48.69708, 48.19626, 47.70021, 47.14557, 46.6379, 46.43077, 46.45227, 46.46962, 46.42054, 46.26455, 46.00459, 45.71205, 45.41908, 45.01678, 44.59761, 44.26378, 44.01034, 43.92813, 44.03938, 44.6082, 45.96941, 47.84619, 49.84009, 51.65982, 53.06986, 54.23803, 55.27684, 56.28798, 57.28409, 58.0529, 58.57428, 58.85722, 58.86063, 58.61768, 58.17303, 57.56319, 56.72721, 55.69675, 54.6655, 53.60663, 52.434, 51.20971, 49.85039, 48.33786, 86.93132, 87.6805, 88.33485, 88.96855, 89.51834, 89.89683, 90.1523, 90.27969, 90.25185, 90.1299, 89.94406, 89.67433, 89.31655, 88.92249, 88.51555, 88.10125, 87.74206, 87.41564, 87.11064, 86.91983),
  indicatorID = c("SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND", "SP.POP.DPND")
)

ggplot(filtered_data, aes(x = date, y = value, color = iso3c))+ 
  geom_line()+ 
  labs(x =  "Year", y =  "Age dependency ratio") + 
  theme_minimal()

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.