First, we load some needed packages, and obtain the latitude and longitude codes for almost all the countries in the world; and then we filter, by region, all those codes that are contained in Portugal:
setwd("C:/Users/MButr/OneDrive/AI4OPT/Maps")
library(ggplot2)
library(tidyverse)
library(dplyr)
library(maps)
library(sf)
library(sp)
library(readr)
mapdat <- map_data("world")
portugal <- filter(mapdat, region == "Portugal")
Then, we load the data set that has the fires information for years 1994 through 2000. From this data set we are interested in whether a specific region of Portugal had or did not have a fire and the longitude and latitude values of the area in which a fire occured.
ff <- read.csv("forestFires.txt")
Now, we generate a map of Portugal’s outline without any fire information included:
df = fortify(portugal)
pt.lim = data.frame(ylim=c(37, 42.5), xlim=c(-10, -6.0))
pt.bbox <- st_bbox(c(xmin=pt.lim$xlim[1],
xmax=pt.lim$xlim[2],
ymin=pt.lim$ylim[1],
ymax=pt.lim$ylim[2]))
ggplot()+
geom_polygon(data = df, aes(x=long, y=lat, group = group),
fill = "green", color = "black", lwd=1)+
coord_fixed(ylim=pt.lim$ylim, xlim=pt.lim$xlim)
The next few blocks of code generate the overlay of the map of Portugal with points were a fire occurred for each of the years from 1994 through 2000.
df = fortify(portugal)
df1 = fortify(ff)
burned94 <- filter(df1, ano1994==1)
df94 = burned94[13:14]
pt.lim = data.frame(ylim=c(37, 42.5), xlim=c(-10, -6.0))
pt.bbox <- st_bbox(c(xmin=pt.lim$xlim[1],
xmax=pt.lim$xlim[2],
ymin=pt.lim$ylim[1],
ymax=pt.lim$ylim[2]))
ggplot()+
geom_polygon(data = df, aes(x=long, y=lat, group = group),
fill = "green", color = "black", lwd=1)+
geom_point(data = df94, aes(x=x,y=y))+
coord_fixed(ylim=pt.lim$ylim, xlim=pt.lim$xlim)
df = fortify(portugal)
df1 = fortify(ff)
burned95 <- filter(df1, ano1995==1)
df95 = burned95[13:14]
pt.lim = data.frame(ylim=c(37, 42.5), xlim=c(-10, -6.0))
pt.bbox <- st_bbox(c(xmin=pt.lim$xlim[1],
xmax=pt.lim$xlim[2],
ymin=pt.lim$ylim[1],
ymax=pt.lim$ylim[2]))
ggplot()+
geom_polygon(data = df, aes(x=long, y=lat, group = group),
fill = "green", color = "black", lwd=1)+
geom_point(data = df95, aes(x=x,y=y))+
coord_fixed(ylim=pt.lim$ylim, xlim=pt.lim$xlim)
df = fortify(portugal)
df1 = fortify(ff)
burned96 <- filter(df1, ano1996==1)
df96 = burned96[13:14]
pt.lim = data.frame(ylim=c(37, 42.5), xlim=c(-10, -6.0))
pt.bbox <- st_bbox(c(xmin=pt.lim$xlim[1],
xmax=pt.lim$xlim[2],
ymin=pt.lim$ylim[1],
ymax=pt.lim$ylim[2]))
ggplot()+
geom_polygon(data = df, aes(x=long, y=lat, group = group),
fill = "green", color = "black", lwd=1)+
geom_point(data = df96, aes(x=x,y=y))+
coord_fixed(ylim=pt.lim$ylim, xlim=pt.lim$xlim)
df = fortify(portugal)
df1 = fortify(ff)
burned97 <- filter(df1, ano1997==1)
df97 = burned97[13:14]
pt.lim = data.frame(ylim=c(37, 42.5), xlim=c(-10, -6.0))
pt.bbox <- st_bbox(c(xmin=pt.lim$xlim[1],
xmax=pt.lim$xlim[2],
ymin=pt.lim$ylim[1],
ymax=pt.lim$ylim[2]))
ggplot()+
geom_polygon(data = df, aes(x=long, y=lat, group = group),
fill = "green", color = "black", lwd=1)+
geom_point(data = df97, aes(x=x,y=y))+
coord_fixed(ylim=pt.lim$ylim, xlim=pt.lim$xlim)
NOTE: we noticed that there were 0 fires in 1998, or least none were recorded. That is why the code used to generate the graph has no additional layers to it. It is basically the code used to generate the outline for the map of POrtugal.
df = fortify(portugal)
df1 = fortify(ff)
burned98 <- filter(df1, ano1998==1)
df98 = burned98[13:14]
pt.lim = data.frame(ylim=c(37, 42.5), xlim=c(-10, -6.0))
pt.bbox <- st_bbox(c(xmin=pt.lim$xlim[1],
xmax=pt.lim$xlim[2],
ymin=pt.lim$ylim[1],
ymax=pt.lim$ylim[2]))
ggplot()+
geom_polygon(data = df, aes(x=long, y=lat, group = group),
fill = "green", color = "black", lwd=1)+
# geom_point(data = df98, aes(x=x,y=y))+
coord_fixed(ylim=pt.lim$ylim, xlim=pt.lim$xlim)
df = fortify(portugal)
df1 = fortify(ff)
burned99 <- filter(df1, ano1999==1)
df99 = burned99[13:14]
pt.lim = data.frame(ylim=c(37, 42.5), xlim=c(-10, -6.0))
pt.bbox <- st_bbox(c(xmin=pt.lim$xlim[1],
xmax=pt.lim$xlim[2],
ymin=pt.lim$ylim[1],
ymax=pt.lim$ylim[2]))
ggplot()+
geom_polygon(data = df, aes(x=long, y=lat, group = group),
fill = "green", color = "black", lwd=1)+
geom_point(data = df99, aes(x=x,y=y))+
coord_fixed(ylim=pt.lim$ylim, xlim=pt.lim$xlim)
df = fortify(portugal)
df1 = fortify(ff)
burned00 <- filter(df1, ano2000==1)
df00 = burned00[13:14]
pt.lim = data.frame(ylim=c(37, 42.5), xlim=c(-10, -6.0))
pt.bbox <- st_bbox(c(xmin=pt.lim$xlim[1],
xmax=pt.lim$xlim[2],
ymin=pt.lim$ylim[1],
ymax=pt.lim$ylim[2]))
ggplot()+
geom_polygon(data = df, aes(x=long, y=lat, group = group),
fill = "green", color = "black", lwd=1)+
geom_point(data = df00, aes(x=x,y=y))+
coord_fixed(ylim=pt.lim$ylim, xlim=pt.lim$xlim)