@@ -54,8 +54,8 @@ s$color <- sprintf("%s %s/%s", s$m_hue, s$m_value, s$m_chroma)
5454
5555Moist color changes with depth.
5656``` {r fig.width=8, fig.height=5}
57- par(mar= c(0,0,2, 0))
58- plotSPC(s, color= 'moist_soil_color', print.id= FALSE, name='', plot. depth.axis= FALSE, width= 0.4)
57+ par(mar = c(0, 0, 2, 0))
58+ plotSPC(s, color = 'moist_soil_color', print.id = FALSE, name = NA, depth.axis = FALSE, width = 0.4)
5959mtext('KSSL data correllated to Holland series', at=0.5, adj = 0)
6060```
6161
@@ -67,7 +67,7 @@ Compute depth-wise transition probability matrix for moist colors. Visualize as
6767# s <- s[idx, ]
6868
6969# generate TP matrix from horizon moist colors
70- tp <- hzTransitionProbabilities(s, name= "color", loopTerminalStates = FALSE)
70+ tp <- hzTransitionProbabilities(s, name = "color", loopTerminalStates = FALSE)
7171
7272# greate graph object
7373par(mar = c(1, 1, 1, 1))
@@ -77,32 +77,31 @@ g <- plotSoilRelationGraph(tp, graph.mode = "directed", vertex.scaling.factor=2,
7777Sketch profiles using same colors as community colors in network graph.
7878``` {r fig.width=8, fig.height=5}
7979# get clustering vector and colors names from graph
80- cl <- data.frame(color= V(g)$name, cluster= V(g)$cluster, stringsAsFactors = FALSE)
80+ cl <- data.frame(color = V(g)$name, cluster = V(g)$cluster, stringsAsFactors = FALSE)
8181
82- # join with SPC
83- # note that we have to extract / join / splice
84- h <- horizons(s)
85- h <- merge(x = h, y = cl, by = 'color', sort = FALSE)
86- replaceHorizons(s) <- h
82+ # join with SPC horizons on `color` column
83+ horizons(s) <- cl
8784
8885# hack re-recreate colors used by plotSoilRelationGraph
8986# good reminder to return more from that function...
9087cols <- colorRampPalette(brewer.pal(n = 9, name = "Set1"))(max(cl$cluster))
9188s$cluster_color <- alpha(cols[s$cluster], 0.65)
9289
9390# profile sketches, colors match communities in graph above
94- par(mar= c(0,0,1, 1))
95- plotSPC(s, color= 'cluster_color', print.id= FALSE, name='hzn_desgn', name .style = 'center-center')
96- mtext('KSSL data correllated to Holland series', at= 0.5, adj = 0)
91+ par(mar = c(0, 0, 1, 1))
92+ plotSPC(s, color = 'cluster_color', print.id = FALSE, name.style = 'center-center', width = 0.35 )
93+ mtext('KSSL data correllated to Holland series', at = 0.5, adj = 0)
9794```
9895
9996
10097
10198Visualize as graph with vertices colored according to soil color.
10299``` {r, fig.width=9, fig.height=9}
103100# join Munsell color notation to graph nodes
104- d <- data.frame(color=V(g)$name, stringsAsFactors = FALSE)
105- d <- plyr::join(d, horizons(s), by = 'color', type='left', match='first')
101+ d <- data.frame(color = V(g)$name, stringsAsFactors = FALSE)
102+
103+ # get the first color
104+ d <- plyr::join(d, horizons(s), by = 'color', type = 'left', match = 'first')
106105V(g)$color <- d$moist_soil_color
107106
108107# prepare labels by converting to HSV
@@ -113,10 +112,10 @@ hsv.cols[, 3] <- ifelse(hsv.cols[, 3] > 0.5, 0, 1)
113112V(g)$label.color <- hsv(hsv.cols[, 1], hsv.cols[, 2], hsv.cols[, 3])
114113
115114# remove loops from graph, retain duplicate paths
116- g <- simplify(g, remove.loops = TRUE, remove.multiple= FALSE)
115+ g <- simplify(g, remove.loops = TRUE, remove.multiple = FALSE)
117116
118117# final plot
119- par(mar= c(0,0,1,0), bg= grey(0.85))
118+ par(mar = c(0,0,1,0), bg = grey(0.85))
120119set.seed(1010101)
121120plot(g, edge.arrow.size = 0.5, vertex.label.cex = 0.55, vertex.label.family = "sans", vertex.label.font=2, edge.color='black')
122121```
@@ -125,14 +124,14 @@ plot(g, edge.arrow.size = 0.5, vertex.label.cex = 0.55, vertex.label.family = "s
125124Simulate moist color sequences using Markov chains derived from transition probability matrix. Weight the TP matrix (and MC?) by working from 1cm slices. Does this make sense? Probably not.
126125``` {r fig.width=8, fig.height=5}
127126# re-make TP matrix, this time including terminal loops
128- s.slices <- slice (s, 0:150 ~ .)
129- tp.loops <- hzTransitionProbabilities(s.slices, name= "color", loopTerminalStates = TRUE)
127+ s.slices <- dice (s, 0:150 ~ .)
128+ tp.loops <- hzTransitionProbabilities(s.slices, name = "color", loopTerminalStates = TRUE)
130129
131130# init new markovchain from TP matrix
132- mc <- new("markovchain", states= dimnames(tp.loops)[[1]], transitionMatrix = tp.loops)
131+ mc <- new("markovchain", states = dimnames(tp.loops)[[1]], transitionMatrix = tp.loops)
133132
134133# investigate the most common surface horizon colors
135- sort(table(h $color[grep('^A', h $hzn_desgn)]), decreasing = TRUE)
134+ sort(table(s $color[grep('^A', s $hzn_desgn)]), decreasing = TRUE)
136135
137136# simulate 30 sequences, starting with the most common A horizon moist color
138137munsell.sequence <- replicate(30, rmarkovchain(n = 150, object = mc, include.t0 = TRUE, t0 = "7.5YR 3/2"))
@@ -141,8 +140,8 @@ munsell.sequence <- replicate(30, rmarkovchain(n = 150, object = mc, include.t0
141140col.sequence <- apply(munsell.sequence, 2, parseMunsell)
142141
143142# visualize
144- par(mar= c(1,0,3, 0))
145- plot(1, 1, type= 'n', axes= FALSE, xlab= '', ylab= '', ylim= c(160, 1), xlim= c(1, 30))
143+ par(mar = c(1, 0, 3, 0))
144+ plot(1, 1, type = 'n', axes = FALSE, xlab = '', ylab = '', ylim = c(160, 1), xlim = c(1, 30))
146145
147146# vectorized functions are the best
148147rect(xleft = col(col.sequence) - 0.5, ybottom = row(col.sequence) -0.5, xright = col(col.sequence) + 0.5, ytop = row(col.sequence) + 0.5, col = col.sequence, border = NA, lty = 0)
@@ -154,13 +153,13 @@ Add most likely sequence.
154153ml <- mostLikelyHzSequence(mc, t0 = "7.5YR 3/2")
155154
156155par(mar=c(1,0,3,0))
157- plot(1, 1, type= 'n', axes= FALSE, xlab= '', ylab= '', ylim= c(160, 1), xlim= c(1, 32))
156+ plot(1, 1, type = 'n', axes = FALSE, xlab = '', ylab = '', ylim = c(160, 1), xlim = c(1, 32))
158157
159158# vectorized functions are the best
160159rect(xleft = col(col.sequence) - 0.5, ybottom = row(col.sequence) -0.5, xright = col(col.sequence) + 0.5, ytop = row(col.sequence) + 0.5, col = col.sequence, border = NA, lty = 0)
161160
162161# stretch most likely sequence... this isn't quite right
163- rect(xleft= 31.5, ybottom = 10 * seq_along(ml) - 0.5, xright = 32.5, ytop = 20 * seq_along(ml) + 0.5, col = parseMunsell(ml))
162+ rect(xleft = 31.5, ybottom = 10 * seq_along(ml) - 0.5, xright = 32.5, ytop = 20 * seq_along(ml) + 0.5, col = parseMunsell(ml))
164163```
165164
166165
@@ -170,7 +169,7 @@ rect(xleft=31.5, ybottom = 10 * seq_along(ml) - 0.5, xright = 32.5, ytop = 20 *
170169Do it again, this time for a soil series with a lot of data: [ Clarksville] ( https://casoilresource.lawr.ucdavis.edu/sde/?series=clarksville ) .
171170``` {r}
172171# get lab / morphologic data
173- x <- fetchKSSL(series= 'clarksville', returnMorphologicData = TRUE, simplifyColors = TRUE)
172+ x <- fetchKSSL(series = 'clarksville', returnMorphologicData = TRUE, simplifyColors = TRUE)
174173
175174# extract SoilProfileCollection
176175s <- x$SPC
@@ -192,19 +191,19 @@ s$color <- sprintf("%s %s/%s", s$m_hue, s$m_value, s$m_chroma)
192191Clarksville moist soil colors.
193192``` {r fig.width=10, fig.height=5}
194193par(mar=c(0,0,2,0))
195- plotSPC(s, color= 'moist_soil_color', print.id= FALSE, name= '', plot. depth.axis= FALSE, width= 0.4, divide.hz= FALSE, lty = 0)
196- mtext('KSSL data correllated to Clarksville series', at= 0.5, adj = 0)
194+ plotSPC(s, color = 'moist_soil_color', print.id = FALSE, name = '', depth.axis = FALSE, width = 0.4, divide.hz = FALSE, lty = 0)
195+ mtext('KSSL data correllated to Clarksville series', at = 0.5, adj = 0)
197196```
198197
199198``` {r fig.width=8, fig.height=8}
200199previewColors(s$moist_soil_color)
201- mtext('KSSL data correllated to Clarksville series: moist colors.', at= 0.5, adj = 0)
200+ mtext('KSSL data correllated to Clarksville series: moist colors.', at = 0.5, adj = 0)
202201```
203202
204203
205204``` {r}
206205# init TP matrix
207- tp.loops <- hzTransitionProbabilities(s, name= "color", loopTerminalStates = TRUE)
206+ tp.loops <- hzTransitionProbabilities(s, name = "color", loopTerminalStates = TRUE)
208207
209208# init new markovchain from TP matrix
210209mc <- new("markovchain", states=dimnames(tp.loops)[[1]], transitionMatrix = tp.loops)
@@ -218,8 +217,8 @@ col.sequence <- apply(munsell.sequence, 2, parseMunsell)
218217
219218Simulated sequence of moist soil colors, starting from * 10YR 4/2* .
220219``` {r fig.width=8, fig.height=5}
221- par(mar= c(1,0,3, 0))
222- plot(1, 1, type= 'n', axes= FALSE, xlab= '', ylab= '', ylim= c(11, 1), xlim= c(1, 30))
220+ par(mar = c(1, 0, 3, 0))
221+ plot(1, 1, type = 'n', axes = FALSE, xlab = '', ylab = '', ylim = c(11, 1), xlim = c(1, 30))
223222
224223rect(xleft = col(col.sequence) - 0.5, ybottom = row(col.sequence) -0.5, xright = col(col.sequence) + 0.5, ytop = row(col.sequence) + 0.5, col = col.sequence)
225224```
0 commit comments