Crear un nuevo dataframe que sea un subconjunto del dataframe original de dfFires. El subconjunto debe contener todos los incendios del Estado de Idaho y las columnas deben ser limitadas para que sólo estén presentes las columnas YEAR_, CAUSE y TOTALACRES. Cambie el nombre de las columnas. Agrupe los datos por CAUSE y YEAR_ y luego resuma por el total de acres quemados. Trazar los resultados.
library(readr)
## Warning: package 'readr' was built under R version 4.2.3
dfFires <- read_csv("StudyArea.csv", col_types = list(UNIT = col_character()), col_names = TRUE)
dfFires
## # A tibble: 439,362 × 14
## FID ORGANIZATI UNIT SUBUNIT SUBUNIT2 FIRENAME CAUSE YEAR_ STARTDATED
## <dbl> <chr> <chr> <chr> <chr> <chr> <chr> <dbl> <chr>
## 1 0 FWS 81682 USCADBR San Diego Bay… PUMP HO… Human 2001 1/1/01 0:…
## 2 1 FWS 81682 USCADBR San Diego Bay… I5 Human 2002 5/3/02 0:…
## 3 2 FWS 81682 USCADBR San Diego Bay… SOUTHBAY Human 2002 6/1/02 0:…
## 4 3 FWS 81682 USCADBR San Diego Bay… MARINA Human 2001 7/12/01 0…
## 5 4 FWS 81682 USCADBR San Diego Bay… HILL Human 1994 9/13/94 0…
## 6 5 FWS 81682 USCADBR San Diego Bay… IRRIGAT… Human 1994 4/22/94 0…
## 7 6 FWS 81682 USCADBR San Diego Bay… FIELD Human 1999 12/6/99 0…
## 8 18 FWS 81682 USCADBR San Diego Bay… CALLA F… Human 2003 6/3/03 0:…
## 9 20 FWS 81682 USCADBR San Diego Bay… OVERPASS Human 2005 8/20/05 0…
## 10 21 FWS 81682 USCADBR San Diego Bay… TRAIN F… Human 2005 12/11/05 …
## # ℹ 439,352 more rows
## # ℹ 5 more variables: CONTRDATED <chr>, OUTDATED <chr>, STATE <chr>,
## # STATE_FIPS <dbl>, TOTALACRES <dbl>
Primero leemos la base de datos correspondiente.
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
dfFires_subc<-dfFires %>%
filter(STATE == 'Idaho') %>%
select("Año" = "YEAR_", "Causa" = "CAUSE","ACRES" = "TOTALACRES")
knitr::kable(head(dfFires_subc, 5))
| Año | Causa | ACRES |
|---|---|---|
| 1987 | Human | 5 |
| 1991 | Natural | 150 |
| 1991 | Human | 800 |
| 1990 | Natural | 2 |
| 1985 | Human | 38 |
Creamos un dataframe que sea el subconjunto de dfFires llamado dfFire_subc.Luego, filtramos por la columna estado a aquellos datos correspondiente a idaho y finalmente renombramos las columnas solicitadas usando select.
dfFires_summary<-dfFires_subc %>%
group_by(Causa,Año) %>%
summarise(Total_Acres_Quemados=sum(ACRES))
## `summarise()` has grouped output by 'Causa'. You can override using the
## `.groups` argument.
knitr::kable(head(dfFires_summary, 5))
| Causa | Año | Total_Acres_Quemados |
|---|---|---|
| Human | 1980 | 71974.7 |
| Human | 1981 | 219362.4 |
| Human | 1982 | 34016.2 |
| Human | 1983 | 48242.5 |
| Human | 1984 | 36837.8 |
Aca lo que hacemos es agrupar los datos en base a la causa y año, para luego resumir el total de acres quemados
library(ggplot2)
ggplot(dfFires_summary, aes(x = Año, y = Total_Acres_Quemados, fill = Causa)) +
geom_col() +
theme_minimal() +
labs(title = 'Total acres quemados por causa y año en Idaho',
x = 'Año',
y = 'Total Acres Quemados') +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
Por ultimo, realizamos el grafico donde en el eje X tenemos la variable año, en Y total acres quemadas y tambien se muestra los datos en base a la causa. Podemos observar que el año en que hubo mayor total acres quemadas corresponde al año 2006 y la causa fue humana, por otro lado el menor valor de total acres quemadas por causas humanas fue en el año 1983.