Skip to content

Commit

Permalink
Corrected accumulated frp y axis legend
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrehsd committed Nov 17, 2019
1 parent a50036e commit 1742a83
Show file tree
Hide file tree
Showing 2 changed files with 351 additions and 570 deletions.
142 changes: 105 additions & 37 deletions Exploratory Data Analysis.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,13 @@ colors_df %>%
cold3 ="#d7c0d7", cold4 = "#e7cce2", cold5 = "#f7d8ed",
hot1 = "#ff4949", hot2 = "#ff6549",
hot3 ="#ff8049", hot4 = "#ff9c49", hot5 = "#ffb749")) +
labs(y = "Quantidade de incêndios", x = "Mês", title = 'Quantidade mensal de incêndios', caption="Fonte: Elaborado pelo Autor") +
labs(y = "Quantidade de incêndios", x = "Mês", title = 'Quantidade mensal de incêndios', subtitle = "em cada ano", caption="Fonte: Elaborado pelo Autor") +
theme(plot.title=element_text(size=10,
face="bold",
family="Arial",
hjust=0.5,
lineheight=1.2), # title
plot.subtitle=element_text(size=10,
plot.subtitle=element_text(size=8,
family="Arial",
face="bold",
hjust=0.5), # subtitle
Expand All @@ -332,8 +332,8 @@ colors_df %>%
axis.text.y=element_text(size=6),
legend.title = element_blank(),
legend.position = "none",
plot.caption = element_text(size = 8)) # Y axis text
# ggsave(paste0(path_ch4, "count-byMonth.png"), dpi = "retina", width = 10, height = 8, units = "cm")
plot.caption = element_text(size = 8)) + # Y axis text
ggsave(paste0(path_ch4, "count-byMonth.png"), dpi = "retina", width = 10, height = 8, units = "cm")
rm(temp)
# rm(colors_df)
Expand Down Expand Up @@ -1132,7 +1132,7 @@ tidy %>%
scale_color_manual(values = c("#ff4949", "#ff9c49", "#ff6549", "#ffb749", "#300836")) +
scale_x_continuous(breaks = seq(from = 0, to = 366, by = 50)) +
geom_dl(aes(label = acq_year), method = list(dl.combine("last.points"), cex = 0.5, hjust = .6, vjust = -.8)) +
labs(title="Curva cumulativa de poder radiativo de fogo emitido", subtitle = "por dia do ano", y="Poder radiativo emitido acumulado (gigawatt)", x= "Dia do ano", caption="Fonte: Elaborado pelo Autor") +
labs(title="Curva cumulativa de poder radiativo de fogo emitido", subtitle = "por dia do ano", y="Poder radiativo emitido acumulado (GW)", x= "Dia do ano", caption="Fonte: Elaborado pelo Autor") +
theme(plot.title=element_text(size=10,
face="bold",
family="Arial",
Expand All @@ -1157,6 +1157,7 @@ tidy %>%
ggsave(paste0(path_ch4, "frpbyDay.png"), dpi = "retina", width = 12, height = 8, units = "cm")
```


Now let's wrap over the frp variable

```{r}
Expand Down Expand Up @@ -1191,8 +1192,8 @@ firms_outlier <-
firms_outlier %>%
ggplot(aes(x = month_name, y = log(frp), group = factor(month(acq_date)))) +
geom_boxplot(outlier.shape = NA) +
geom_point(data = function(x) dplyr::filter_(firms_outlier, ~ outlier), position = 'jitter', size = 1/100, alpha = 1/15) +
labs(title="Boxplot de Poder Radiativo de Fogo", subtitle = "para cada mês do ano", y="Poder radiativo emitido log(MW)", x= "Mês", caption="Fonte: Elaborado pelo Autor") +
geom_point(data = function(x) dplyr::filter_(firms_outlier, ~ outlier), position = 'jitter', size = 1/100, alpha = 1/20) +
labs(title="Boxplot - Poder Radiativo de Fogo", subtitle = "para cada mês do ano", y="Poder radiativo emitido log(MW)", x= "Mês", caption="Fonte: Elaborado pelo Autor") +
theme(plot.title=element_text(size=10,
face="bold",
family="Arial",
Expand All @@ -1211,60 +1212,127 @@ firms_outlier %>%
legend.text = element_blank(),
legend.position = "none",
plot.caption = element_text(size = 6)) + # Y axis text
ggsave(paste0(path_ch4, "bosplot-frp.png"), dpi = "retina", width = 12, height = 8, units = "cm")
ggsave(paste0(path_ch4, "boxplot-frp.png"), dpi = "retina", width = 12, height = 8, units = "cm")
```


```{r}
firms %>%
ggplot() +
geom_density(aes(x = brightness, alpha = 0.5)) +
geom_density(aes(x = bright_t31, alpha = 0.5)) +
# scale_color_manual(values = cbp1) +
scale_fill_manual(values = cbp1)
```
q1_frp <- quantile(firms$frp, .25)
q3_frp <- quantile(firms$frp, .75)
iqr_frp <- IQR(firms$frp)
One thing that we do not see until this point was the average fire radiative power along the days of the year. However, as we have many extreme cases, i.e., outliers, we are gonna remove them before plotting the statistics

```{r}
q1_brightness <- quantile(firms$brightness, .25)
q3_brightness <- quantile(firms$brightness, .75)
iqr_brightness <- IQR(firms$brightness)
q1 <- quantile(firms$frp, .25)
q3 <- quantile(firms$frp, .75)
iqr <- IQR(firms$frp)
mild_low_frp <- q1_frp - 1.5 * iqr_frp
mild_high_frp <- q3_frp + 1.5 * iqr_frp
mild_low <- q1 - 1.5 * iqr
mild_high <- q3 + 1.5 * iqr
mild_low_brightness <- q1_brightness - 1.5 * iqr_brightness
mild_high_brightness <- q3_brightness + 1.5 * iqr_brightness
clean_modis <- firms[firms$frp > mild_low & firms$frp < mild_high, ] #rows
clean_firms <- firms[firms$frp > mild_low_frp && firms$frp < mild_high_frp ||
firms$brightness > mild_low_brightness && firms$brightness < mild_high_brightness, ] #rows
mean_frp_nasa <- clean_modis %>%
mean_nasa <- clean_firms %>%
mutate(acq_year = year(acq_date),
acq_week = week(acq_date)) %>%
select(acq_year, acq_week, frp) %>%
select(acq_year, acq_week, frp, brightness) %>%
group_by(acq_year, acq_week) %>%
summarise(mean_frp = mean(frp))
summarise(mean_frp = mean(frp),
mean_brightness = mean(brightness))
```

```{r}
splitted <- mean_frp_nasa %>% select(acq_year, acq_week, mean_frp)
splitted_frp <- mean_nasa %>% select(acq_year, acq_week, mean_frp)
splitted_brightness <- mean_nasa %>% select(acq_year, acq_week, mean_brightness)
# Using `do` function to replace NAs values with the last records value
tidy <- splitted %>% spread(key = acq_year, value = mean_frp) %>% do(zoo::na.locf(.))
tidy$`2019`[40:nrow(tidy)] <- NA
tidy <- tidy %>%
tidy_frp <- splitted_frp %>% spread(key = acq_year, value = mean_frp) %>% do(zoo::na.locf(.))
tidy_brightness <- splitted_brightness %>% spread(key = acq_year, value = mean_brightness) %>% do(zoo::na.locf(.))
tidy_frp$`2019`[40:nrow(tidy_frp)] <- NA
tidy_brightness$`2019`[40:nrow(tidy_brightness)] <- NA
tidy_frp <- tidy_frp %>%
gather("2015", "2016", "2017", "2018", "2019", key = "acq_year", "value" = mean_frp)
tidy_brightness <- tidy_brightness %>%
gather("2015", "2016", "2017", "2018", "2019", key = "acq_year", "value" = mean_brightness)
```

```{r}
tidy %>%
tidy_frp %>%
ggplot(aes(x = acq_week, y = mean_frp, col = acq_year)) +
geom_line() +
scale_color_manual(values = c("grey", "grey", "grey", "grey", "red")) +
scale_x_continuous("Week of the year", breaks = seq(from = 0, to = 52, by = 4)) +
scale_y_continuous("Fire Radiative power")
geom_line(alpha = 0.6) +
scale_color_manual(values = c("grey", "grey", "grey", "grey", "#bd750e")) +
scale_x_continuous("Semana do ano", breaks = seq(from = 0, to = 52, by = 4)) +
geom_dl(aes(label = acq_year), method = list(dl.combine("last.bumpup"), cex = .5)) +
labs(title="Poder Radiativo de Fogo Médio", subtitle = "por semana", y="Média de Poder Radiativo de Fogo (MW)", caption="Fonte: Elaborado pelo Autor") +
theme(plot.title=element_text(size=10,
face="bold",
family="Arial",
hjust=0.5,
lineheight=1.2), # title
plot.subtitle=element_text(size=8,
family="Arial",
face="bold",
hjust=0.5), # subtitle
axis.title.x=element_text(size=8), # X axis title
axis.title.y=element_text(size=8), # Y axis title
axis.text.x=element_text(size=5,
vjust=.5), # X axis text
axis.text.y=element_text(size=4),
legend.title = element_blank(),
legend.text = element_blank(),
legend.position = "none",
plot.caption = element_text(size = 6)) + # Y axis text
ggsave(paste0(path_ch4, "frp-weekly.png"), dpi = "retina", width = 12, height = 8, units = "cm")
```

```{r}
tidy_brightness %>%
ggplot(aes(x = acq_week, y = mean_brightness, col = acq_year)) +
geom_line(alpha = 0.6) +
scale_color_manual(values = c("grey", "grey", "grey", "grey", "#bd750e")) +
scale_x_continuous("Semana do ano", breaks = seq(from = 0, to = 52, by = 4)) +
geom_dl(aes(label = acq_year), method = list(dl.combine("last.bumpup"), cex = .5)) +
labs(title="Temperatura Média estimada nos pixels", subtitle = "por semana", y="Temperatura Média (K)", caption="Fonte: Elaborado pelo Autor") +
theme(plot.title=element_text(size=10,
face="bold",
family="Arial",
hjust=0.5,
lineheight=1.2), # title
plot.subtitle=element_text(size=8,
family="Arial",
face="bold",
hjust=0.5), # subtitle
axis.title.x=element_text(size=8), # X axis title
axis.title.y=element_text(size=8), # Y axis title
axis.text.x=element_text(size=5,
vjust=.5), # X axis text
axis.text.y=element_text(size=4),
legend.title = element_blank(),
legend.text = element_blank(),
legend.position = "none",
plot.caption = element_text(size = 6)) + # Y axis text
ggsave(paste0(path_ch4, "brightness-weekly.png"), dpi = "retina", width = 12, height = 8, units = "cm")
```



```{r}
firms %>%
ggplot() +
geom_density(aes(x = brightness, alpha = 0.5)) +
geom_density(aes(x = bright_t31, alpha = 0.5)) +
# scale_color_manual(values = cbp1) +
scale_fill_manual(values = cbp1)
```


One thing that we do not see until this point was the average fire radiative power along the days of the year. However, as we have many extreme cases, i.e., outliers, we are gonna remove them before plotting the statistics

```{r}
clean_modis %>%
group_by(acq_date) %>%
Expand Down
Loading

0 comments on commit 1742a83

Please sign in to comment.