top of page
Writer's pictureGeorge

Data Analysis using R: Visualizing with ggplot the evolution of carbon dioxide content over time

R is one of the most powerful tools used in data analysis and statistical modeling. This short guide, demonstrates how to analyze and visualize quantitative data in R.

It's a time-series analysis given the changes in carbon dioxide over time.


Sample Question

Visualize with ggplot in an appropriate way the evolution of carbon dioxide content (the variable co2_ppm) during the entire period. Use the decimal_date variable as the time. Also, enter appropriate chart and axis headings.


The dataset is in two columns, year (1959 - 2023) and Growth (co2_ppm value corresponding to each year)


1959 0.94 0.11 1960 0.50 0.11 1961 0.96 0.11 1962 0.64 0.11 1963 0.71 0.11 1964 0.32 0.11 1965 1.06 0.11 1966 1.28 0.11 1967 0.70 0.11 1968 1.06 0.11 1969 1.35 0.11 1970 1.00 0.11 1971 0.81 0.11 1972 1.74 0.11 1973 1.18 0.11 1974 0.95 0.11 1975 1.09 0.11 1976 0.79 0.11 1977 2.15 0.11 1978 1.30 0.11 1979 1.83 0.11 1980 1.68 0.11 1981 1.43 0.11 1982 0.86 0.11 1983 2.36 0.11 1984 1.51 0.11 1985 1.21 0.11 1986 1.47 0.11 1987 2.06 0.11 1988 2.24 0.11 1989 1.24 0.11 1990 1.20 0.11 1991 1.05 0.11 1992 0.49 0.11 1993 1.36 0.11 1994 1.95 0.11 1995 2.01 0.11 1996 1.24 0.11 1997 1.91 0.11 1998 2.97 0.11 1999 0.92 0.11 2000 1.62 0.11 2001 1.62 0.11 2002 2.51 0.11 2003 2.27 0.11 2004 1.59 0.11 2005 2.57 0.11 2006 1.69 0.11 2007 2.31 0.11 2008 1.54 0.11 2009 2.00 0.11 2010 2.30 0.11 2011 1.92 0.11 2012 2.65 0.11 2013 1.99 0.11 2014 2.17 0.11 2015 2.95 0.11 2016 3.03 0.11 2017 1.89 0.11 2018 2.85 0.11 2019 2.49 0.11 2020 2.27 0.11 2021 2.37 0.11 2022 1.81 0.11 2023 3.36 0.11


Solution

Start by loading the required library:

library(ggplot2)


In R, set the dataframe as follows:

data <- data.frame(

  Year = 1959:2023,

  Growth = c(

    0.940.500.960.640.710.321.061.280.701.06,

    1.351.000.811.741.180.951.090.792.151.30,

    1.831.681.430.862.361.511.211.472.062.24,

    1.241.201.050.491.361.952.011.241.912.97,

    0.921.621.622.512.271.592.571.692.311.54,

    2.002.301.922.651.992.172.953.031.892.85,

    2.492.272.371.813.36

  )

)


Next, create the plot

ggplot(data = data, aes(x = Year, y = Growth)) +

  geom_line() +

  labs(title = "Evolution of Carbon Dioxide Content Over Time",

       x = "Year",

       y = "Growth (ppm)")


The plot should look like this based on the given data:






Comments


Joz Art Logo24=portrait.png
bottom of page