library(readr)
library(ggplot2)
carbon_emissions <- read_csv("Desktop/RWorkingDirectory/Working Directory/carbon_emissions.csv")
## Rows: 8960 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): country, iso_code
## dbl (6): year, co2_per_capita, population, gdp_per_capita, energy_per_capita...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

Part I: Scatterplot With Linear Model

plot <- ggplot(data=carbon_emissions, aes(x = gdp_per_capita, y = co2_per_capita)) + geom_smooth(method = "lm") + geom_point() + 
  labs(x = "GDP per Capita", y = "Carbon Emissions per Capita") +
  ggtitle("Countries GDP Effect on Carbon Emissions")
plot
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 2612 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 2612 rows containing missing values (`geom_point()`).

The line slopes upwards from the lower-left corner to the upper-right corner. That indicates a positive relationship, suggesting that as GDP per capita increases, carbon emissions per capita tend to increase as well.

Part II: Coefficient Plot of Multivariate Linear Model

library(broom)

model <- lm(co2_per_capita ~ gdp_per_capita + energy_per_capita, data=carbon_emissions)

coefs <- tidy(model, conf.int = TRUE)

ggplot(coefs[2:3,], aes(x = term, y = estimate)) +
  geom_pointrange(aes(ymin = conf.low, ymax = conf.high)) +
  geom_hline(yintercept = 0, linetype = "dashed") +
  coord_flip() +
  labs(
    x = "Predictors",
    y = "Estimated Coefficients",
    title = "Predictors of Carbon Emissions per Capita") 

The coefficients tell you how much carbon emissions per capita are expected to change for a one-unit change in the predictor variable while holding all other variables constant.

The lines extending from each point represent the 95% confidence intervals for the estimated coefficients. If the lines do not cross the zero line, it suggests that the corresponding coefficient is statistically significant at the 95% confidence level.