Last updated: 2021-12-14
This code explores the distribution and influence of interpolated area data.
library(tidyverse)
area <- read.csv("../output_big/hectares_state_usda_usgs_20200404.csv") %>%
mutate(interp = ifelse(SOURCE_DESC == "interp", "yes", "no")) # fix interp column
# calculate interpolated area by crop
area_crop_tot <- area %>%
group_by(USGS_group) %>%
summarise(ha_tot = sum(ha, na.rm=T))
area_crop_sum <- area %>%
group_by(USGS_group, interp) %>%
summarise(ha = sum(ha, na.rm=T)) %>%
left_join(area_crop_tot) %>%
pivot_wider(names_from = interp, values_from = ha) %>%
mutate(perc_interp = (yes/ha_tot)*100)
Joining, by = "USGS_group"
# calculate interpolated area over the whole sample
area_tot <- area %>%
summarise(ha_tot = sum(ha, na.rm=T))
area_sum <- area %>%
group_by(interp) %>%
summarise(ha = sum(ha, na.rm=T)) %>%
mutate(ha_tot = area_tot$ha_tot) %>%
pivot_wider(names_from = interp, values_from = ha) %>%
mutate(perc_interp = (yes/ha_tot)*100)
# repeat calcs for only census years
area_cen <- filter(area, YEAR %in% c(1997, 2002, 2007, 2012, 2017))
area_crop_tot_cen <- area_cen %>%
group_by(USGS_group) %>%
summarise(ha_tot = sum(ha, na.rm=T))
area_crop_sum_cen <- area_cen %>%
group_by(USGS_group, interp) %>%
summarise(ha = sum(ha, na.rm=T)) %>%
left_join(area_crop_tot) %>%
pivot_wider(names_from = interp, values_from = ha) %>%
mutate(perc_interp = (yes/ha_tot)*100)
Joining, by = "USGS_group"
sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Catalina 10.15.7
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] forcats_0.4.0 stringr_1.4.0 dplyr_0.8.3 purrr_0.3.2
[5] readr_1.3.1 tidyr_1.1.0 tibble_2.1.3 ggplot2_3.2.0
[9] tidyverse_1.2.1
loaded via a namespace (and not attached):
[1] Rcpp_1.0.6 cellranger_1.1.0 pillar_1.4.2 compiler_3.6.1
[5] tools_3.6.1 digest_0.6.20 lubridate_1.7.4 jsonlite_1.6
[9] evaluate_0.14 lifecycle_0.2.0 nlme_3.1-140 gtable_0.3.0
[13] lattice_0.20-38 pkgconfig_2.0.2 rlang_0.4.7 cli_1.1.0
[17] rstudioapi_0.10 yaml_2.2.0 haven_2.1.1 xfun_0.8
[21] withr_2.1.2 xml2_1.2.0 httr_1.4.2 knitr_1.23
[25] hms_0.5.0 generics_0.0.2 vctrs_0.3.2 grid_3.6.1
[29] tidyselect_1.1.0 glue_1.3.1 R6_2.4.0 readxl_1.3.1
[33] rmarkdown_1.14 modelr_0.1.4 magrittr_1.5 ellipsis_0.2.0.1
[37] backports_1.1.4 scales_1.0.0 htmltools_0.3.6 rvest_0.3.4
[41] assertthat_0.2.1 colorspace_1.4-1 stringi_1.4.3 lazyeval_0.2.2
[45] munsell_0.5.0 broom_0.5.2 crayon_1.3.4
This R Markdown site was created with workflowr