Assignment7

Author

Carla

#main libraries
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.2.1     ✔ readr     2.2.0
✔ forcats   1.0.1     ✔ stringr   1.6.0
✔ ggplot2   4.0.3     ✔ tibble    3.3.1
✔ lubridate 1.9.5     ✔ tidyr     1.3.2
✔ purrr     1.2.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(dplyr)

#library to find the temp_carbon data set
library(dslabs)

#library to construct the carbon_scatterplot
library(ggplot2)

#libraries to have the carbon_scatterplot interactive
library(ggfortify)
library(plotly)

Attaching package: 'plotly'

The following object is masked from 'package:ggplot2':

    last_plot

The following object is masked from 'package:stats':

    filter

The following object is masked from 'package:graphics':

    layout
#retrieve the temp_carbon dataset
data(temp_carbon)

#retrieve the first few values of temp_carbon dataset for intial analysis
head(temp_carbon)
  year temp_anomaly land_anomaly ocean_anomaly carbon_emissions
1 1880        -0.11        -0.48         -0.01              236
2 1881        -0.08        -0.40          0.01              243
3 1882        -0.10        -0.48          0.00              256
4 1883        -0.18        -0.66         -0.04              272
5 1884        -0.26        -0.69         -0.14              275
6 1885        -0.25        -0.56         -0.17              277
#clean the temp_carbon data set from NA values specifically from the year, temp_anomaly, and carbon_emissions variables for more accurate visualization.
temp_carbon <- temp_carbon %>% filter(!is.na(year) & !is.na(temp_anomaly) &                 !is.na(carbon_emissions))

#carbon_scatterplot constructed from year, temp_anomaly, and carbon_emissions to demonstrate the ongoing trend of increasing temperatures and carbon emissions since 1880 to 2000 and beyond. 
carbon_scatterplot <- ggplot(temp_carbon, aes(x = year, y = temp_anomaly, color = carbon_emissions)) + geom_point(alpha = 1) + 
  geom_smooth(se = FALSE, color = "black") +
  labs(
    title = "Temperature Increase Over Time with Ongoing Trend",
    x = "Years",
    y = "Temperature Increases Reported",
    color = "Carbon Emissions Reported",
    caption = "From the temp_carbon data set from dslabs"
  )

#ggplotly function to have the carbon_scatterplot interactive
ggplotly(carbon_scatterplot)
`geom_smooth()` using method = 'loess' and formula = 'y ~ x'

I used the temp_carbon data set from the dslabs library to create this visualization to demonstrate the rising temperatures and carbon emissions reported since 1880 to 2000 and beyond. I created this graph using the year, temp_anomalies, and carbon_emissions variables to construct a scatter plot to better visualize the sharp ongoing trend. What first interests me that since the 1880 there is recorded information of the hypothetical carbon emissions, and temperatures, that are quite obviously low for good reason. In contrast noticing since 1960s the trend shoots upward more steeply in comparison to the slow, but steady increase in temperatures and carbon emissions before 1960. Having filtered out the NA values to increase visualization clarity, the carbon and temperature increase have since drastically increased since 1880, giving to show how climate change has been slowly rising since the nineteen hundreds.