Given the limitations and uncertainties associated with any
predictive model, it’s advisable to treat the predictions as one
possible scenario rather than a definitive outcome. However, I would
hope for the predictions to be closer to reality than not.
library(ggplot2)
# Load data from CSV file
data <- read.csv("GlobalCO2Emissions.csv")
# Ensure variables are named correctly
names(data)[names(data) == "Year"] <- "year"
names(data)[names(data) == "Emissions"] <- "emissions"
# Fit quadratic model
model <- lm(emissions ~ year + I(year^2), data = data)
# Make predictions for 2030-2039
future_years <- 2030:2039
predictions <- predict(model, newdata = data.frame(year = future_years))
# Create a data frame for historical data
historical_data <- data.frame(year = data$year, emissions = data$emissions, type = "Historical")
# Create a data frame for predicted data
predicted_data <- data.frame(year = future_years, emissions = predictions, type = "Predicted")
# Combine data frames
combined_data <- rbind(historical_data, predicted_data)
# Create the plot
ggplot(combined_data, aes(x = year, y = emissions, color = type)) +
geom_point() +
geom_line() +
labs(title = "Global CO₂ Emissions: Linear Regression Model Prediction 2030-2039",
x = "Year", y = "Emissions GtCO₂",
color = "Data Type")
