-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.R
More file actions
51 lines (39 loc) · 2.11 KB
/
Test.R
File metadata and controls
51 lines (39 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
pkgTest <- function(x)
{
if (!require(x, character.only = TRUE))
{
install.packages(x,dep=TRUE)
if (!require(x, character.only = TRUE)) stop("Package not found")
}
}
pkgTest("rgl") # install if nessesery
# this code uses cubes and coluers them with amounts of Red Green & Blue for each soil component
Soil.Testing <- read.csv("Soil Testing.csv") # Test File
Wid <- max(Soil.Testing$Width) ## max vals
Len <- max(Soil.Testing$Length)
Depth <- max(Soil.Testing$Depth)
Fild <- NA ## Setup blank Data
Fild$pram <- list(1:Wid, 1:Len, 1:Depth)
for (Depth in Fild$pram[[3]]) {
Fild$Silt[Depth] <- list(matrix(0,max(Fild$pram[[1]]),max(Fild$pram[[2]])))
Fild$Sand[Depth] <- list(matrix(0,max(Fild$pram[[1]]),max(Fild$pram[[2]])))
Fild$Clay[Depth] <- list(matrix(0,max(Fild$pram[[1]]),max(Fild$pram[[2]])))
}
# Make Data
for (Rw in 1:nrow(Soil.Testing)) {
Fild$Silt[[Soil.Testing$Depth[Rw]]][Soil.Testing$Width[Rw], Soil.Testing$Length[Rw]] <- round(Soil.Testing$Silt[Rw]*255,0)
Fild$Sand[[Soil.Testing$Depth[Rw]]][Soil.Testing$Width[Rw], Soil.Testing$Length[Rw]] <- round(Soil.Testing$Sand[Rw]*255,0)
Fild$Clay[[Soil.Testing$Depth[Rw]]][Soil.Testing$Width[Rw], Soil.Testing$Length[Rw]] <- round(Soil.Testing$Clay[Rw]*255,0)
}
with(Fild$pram, plot3d(x = Fild$pram[[1]], y = Fild$pram[[2]], Fild$pram[[3]] + 1, type = "n", size = 0, col = "red", cex = 2, box = FALSE, aspect = "iso")) # Makes a corectly sized plot
planes3d(a = c(0,max(Fild$pram[[1]])), b = c(0,max(Fild$pram[[2]])), c = -1, d = max(Fild$pram[[3]]) + .5, col = "chocolate4", alpha = 0.8) # puts a soil top on it
## This last section can he run alone just to make cubes
for (Len in Fild$pram[[1]]) {
for (Wid in Fild$pram[[2]]) {
for (Depth in Fild$pram[[3]]) {
shade3d( translate3d( scale3d( cube3d(col = rgb(Fild$Sand[[Depth]][Len,Wid], Fild$Silt[[Depth]][Len,Wid], Fild$Clay[[Depth]][Len,Wid], maxColorValue = 255), alpha = 0.3), .5, .5, .5), Len, Wid, Depth ) )
}
}
} ## to hear
### expand window manually
legend3d("bottom", legend = c('% Sand', '% Silt', '% Clay'), pch = 16, col = c("red", "green", "blue"), cex=.8, inset=c(0.0001))