Here is my code below. I want to plot CO2 distribution over the South African map.
Loading packages
library(tidyverse)
theme_set(theme_bw())
library("sf")
library("rnaturalearth")
library("rnaturalearthdata")
Assigning world to the countries of the world data
world <- ne_countries(scale = "medium", returnclass = "sf")
Reading the local file with CO2 and geographic coordinates (Lon and Lat)
SA_CO2 <- read_csv2("C:/Users/Xolile Ncipha/Documents/SA_CO2_DJF_2004_2009.csv")
Converting the data frame to a sf object and the coordinate reference system projection to WGS84, which is the CRS code #4326.
(SA_CO2 <- st_as_sf(SA_CO2, coords = c("Lon", "Lat"), crs = 4326, agr = "constant"))
Plotting the map and overlaying it with CO2 dataThe output of my code/script.
ggplot(data = world) + geom_sf() + geom_sf(data = SA_CO2, aes(fill = CO2)) +
CO2 legend
scale_fill_gradientn(colors = sf.colors(10)) +
Confining the map to South African domain.
coord_sf(xlim = c(15, 35), ylim = c(-36, -22.3), expand = FALSE) +
Axis labels
xlab("Longitude") + ylab("Latitude")
The results is the geographic points on the map. I don't get the overlay of CO2 data and its spatial distribution. I have attached a picture of the resulting map and the spatial data.