Going fast! #DataquestChallenge Premium Annual Offer:
500 get 50% & the next 1000 get 40% off.
GET OFFER CODE

Forest Fires Data

library(readr)
library(tidyverse)
library(lubridate)
library(ggthemes)
library(ggpubr)
theme_set(theme_solarized())

ff = read_csv("forestfires.csv")


months = c("Jan","Feb","Mar","Apr","Mai","Jun","Jul","Aug","Sep","Oct","Nov","Dec")

days = c("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun")

ff %>% mutate(across(month:day, as.factor)) %>% mutate(month = fct_relevel(month,
      "jan" , "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec" ), day =
        fct_relevel(day, "mon", "tue", "wed", "thu", "fri", "sat", "sun")) -> ff

summary(ff)

ff %>% count(month) %>% ggplot(aes(month,n)) + geom_col() 

ff %>% count(day)  %>% ggplot(aes(day,n)) + geom_col() 



ff %>% group_by(month) %>% summarise(across(FFMC:area, mean))

#values of fire weather index : DC, drought code; DMC, duff moisture code; FFMC, fine fuel moisture code, ISI initial spread index

#https://bit.ly/3eQA9ba

library(FactoMineR)
library(factoextra)


res.pca <- PCA(ff, quali.sup = 3:4, quanti.sup = 1:2)

barplot(res.pca$eig[,2], type = "b")

res.pca$var

fviz_pca_biplot(res.pca, geom = "point", habillage = ff$month, palette = "Reds", ggtheme=theme_clean(), alpha.var="cos2")

#highest contrib and cor first axis temp , dim2 RH


#plotting by month



ff %>% pivot_longer(cols = FFMC:area, names_to = "measure") %>% 
  group_by(month) %>% 
  ggplot(aes(measure, value)) + 
  stat_summary(fun=mean, geom="bar",aes(fill=measure)) +
  facet_wrap(~ month) + theme_solarized() + rotate_x_text()

#highest values of DMC during Aug-Sep, FFMC Aug

#relationship between area and other variables

library(GGally)


ggduo(ff, columnsX = 5:12, columnsY = 13) 

#oultliers : biggest fires, DMC and FFMC values stand out
ff[ff$area > 600,]

ggduo(ff[ff$area < 600,], columnsX = 5:12, columnsY = 13)

#the area is not significantly correlated to any of the variables

library(corrplot)

corrplot(cor(ff[,5:13]))

ff.pdf (558.9 KB)