Created
March 23, 2024 21:26
-
-
Save jlisic/682e2d8129a023d7b01dade816420051 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(cdlTools) | |
library(dplyr) | |
library(magrittr) | |
library(ggplot2) | |
years <- 2008:2023 | |
state <- 'maryland' | |
# Terra! | |
cdl.raster <- getCDL(state,years,location="~/CDL",returnType = 'terra') | |
# Metadata! | |
maryland_metadata = list() | |
for( year in 2008:2023) { | |
maryland_metadata[[as.character(year)]] = metadata('maryland',year) | |
} | |
# the crop to get | |
# Note, some things are not perfect, e.g. "Corn 1" for 2010 | |
crop = 'Soybeans' | |
value = sapply( maryland_metadata, | |
function(x) x$Cell[ x$Cell[,1] == crop,"User's Accuracy"] ) | |
# a little bit of data cleaning and formatting | |
value = unlist(value) | |
acc_df= data.frame( | |
Year = as.numeric(names(value)), | |
Accuracy = as.numeric(value) | |
) | |
# now for some plots | |
ggplot( aes(x=Year, y=Accuracy), data=acc_df) + geom_line() + ylim(0,100) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment