Skip to content

Commit

Permalink
mostly for my own curiosity, but we will have to address eventually
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanbeaudette committed Mar 9, 2023
1 parent 6517954 commit 2af12a4
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions misc/SSURGO-ST-edition-eval.R
Original file line number Diff line number Diff line change
@@ -1,24 +1,41 @@
library(soilDB)
library(lattice)
library(latticeExtra)
library(tactile)

x <- SDA_query("SELECT soiltaxedition, SUM((comppct_r / 100) * muacres) AS ac from mapunit JOIN component on mapunit.mukey = component.mukey WHERE soiltaxedition IS NOT NULL GROUP BY soiltaxedition ORDER BY ac DESC;")
# let SDA do the work
# approx. MU acres by ST edition
x <- SDA_query("SELECT
soiltaxedition, SUM((comppct_r / 100) * muacres) AS ac
FROM mapunit AS mu
JOIN component AS co ON mu.mukey = co.mukey
WHERE soiltaxedition IS NOT NULL
GROUP BY soiltaxedition
ORDER BY ac DESC;")


# remove 'edition' for simpler axes labels
x$ed <- gsub(pattern = ' edition', replacement = '', x$soiltaxedition)

# numerical ordering
x$ed <- factor(x$ed, levels = c('first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth', 'tenth', 'eleventh', 'twelfth', 'thirteenth'))

# sort by acreage
x$ed.sorted <- factor(x$ed, levels = x$ed[order(x$ac)])


p1 <- dotplot(ed ~ ac / 1e6, data = x, par.settings = tactile.theme(), xlab = 'Millions of Acres (SSURGO)', ylab = 'ST Edition')
# unsorted
p1 <- dotplot(ed ~ ac / 1e6, data = x, par.settings = tactile.theme(), xlab = 'Millions of Acres', ylab = 'ST Edition', type = c('p', 'g'))

# sorted
p2 <- dotplot(ed.sorted ~ ac / 1e6, data = x, par.settings = tactile.theme(), xlab = 'Millions of Acres', ylab = 'ST Edition', type = c('p', 'g'))

# combine figures
p <- c(p1, p2, x.same = TRUE)

p2 <- dotplot(ed.sorted ~ ac / 1e6, data = x, par.settings = tactile.theme(), xlab = 'Millions of Acres (SSURGO)', ylab = 'ST Edition')
# add scales to both panels
p <- update(p, scales = list(alternating = 3), main = 'Editions of KST\nFY23 SSURGO')

p <- c(p1, p2)
# neat
print(p)

p <- update(p, scales = list(alternating = 3))

p

0 comments on commit 2af12a4

Please sign in to comment.