Skip to content

Commit f7e3194

Browse files
committed
Add the option of choosing colours for plots.
1 parent eb3f3e6 commit f7e3194

18 files changed

+267
-100
lines changed

R/basic_metrics_pc.R

Lines changed: 93 additions & 59 deletions
Large diffs are not rendered by default.

R/plotting_metrics_pc.R

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
#' \code{\link{tree_height_pc}}. Only relevant if a dtm is provided.
1818
#' @param OUT_path A character with the path to the folder where the figures
1919
#' should be saved (default = current folder).
20+
#' @param plotcolors list of three colors for plotting. Only relevant when plot
21+
#' = TRUE. The tree points, the lowest point height and the DTM points are
22+
#' colored by the first, second and third element of this list respectively.
2023
#'
2124
#' @return A list with in the first element a numeric containing the tree height
2225
#' values for each tree point cloud. In the second element there is the list
@@ -41,7 +44,8 @@
4144
#' )
4245
#' }
4346
plot_tree_height_pcs <- function(PCs_path, extension = ".txt", dtm = NA,
44-
r = 5, OUT_path = "./") {
47+
r = 5, OUT_path = "./",
48+
plotcolors = c("#000000","#08aa7c","#fac87f")) {
4549
file_paths <- list.files(PCs_path,
4650
pattern = paste("*", extension, sep = ""),
4751
full.names = TRUE
@@ -55,7 +59,7 @@ plot_tree_height_pcs <- function(PCs_path, extension = ".txt", dtm = NA,
5559
for (i in 1:length(file_names)) {
5660
print(paste("processing ", file_names[i]))
5761
pc <- read_tree_pc(file_paths[i])
58-
out <- tree_height_pc(pc, dtm, r, TRUE)
62+
out <- tree_height_pc(pc, dtm, r, TRUE, plotcolors)
5963
filename <- paste(OUT_path, "tree_height_",
6064
strsplit(file_names[i], extension)[[1]], ".jpeg",
6165
sep = ""
@@ -97,6 +101,10 @@ plot_tree_height_pcs <- function(PCs_path, extension = ".txt", dtm = NA,
97101
#' \code{\link{tree_height_pc}}. Only relevant if a dtm is provided.
98102
#' @param OUT_path A character with the path to the folder where the figures
99103
#' should be saved (default = current folder).
104+
#' @param plotcolors list of three colors for plotting. Only relevant when plot
105+
#' = TRUE. The stem points, fitted circle, the concave hull and the estimated
106+
#' center are colored by the first, second and third and fourth element of
107+
#' this list respectively.
100108
#'
101109
#' @return A list with in the first element a numeric containing the diameter
102110
#' values for each tree point cloud, the second element the residuals on the
@@ -124,7 +132,9 @@ plot_tree_height_pcs <- function(PCs_path, extension = ".txt", dtm = NA,
124132
#' }
125133
plot_circle_fit_pcs <- function(PCs_path, extension = ".txt",
126134
slice_height = 1.3, slice_thickness = 0.06,
127-
dtm = NA, r = 5, OUT_path = "./") {
135+
dtm = NA, r = 5, OUT_path = "./",
136+
plotcolors = c("#000000", "#1c027a","#08aa7c",
137+
"#fac87f")) {
128138
file_paths <- list.files(PCs_path,
129139
pattern = paste("*", extension, sep = ""),
130140
full.names = TRUE
@@ -141,7 +151,7 @@ plot_circle_fit_pcs <- function(PCs_path, extension = ".txt",
141151
print(paste("processing ", file_names[i]))
142152
pc <- read_tree_pc(file_paths[i])
143153
out <- diameter_slice_pc(pc, slice_height, slice_thickness, dtm = dtm,
144-
r = r, plot = TRUE)
154+
r = r, plot = TRUE, plotcolors)
145155
filename <- paste(OUT_path, "circle_",
146156
strsplit(file_names[i], extension)[[1]], "_",
147157
as.character(slice_height), "_",
@@ -183,6 +193,10 @@ plot_circle_fit_pcs <- function(PCs_path, extension = ".txt",
183193
#' \code{\link{tree_height_pc}}. Only relevant if a dtm is provided.
184194
#' @param OUT_path A character with the path to the folder where the figures
185195
#' should be saved (default = current folder).
196+
#' @param plotcolors list of three colors for plotting. Only relevant when plot
197+
#' = TRUE. The stem points, fitted circle, the concave hull and the estimated
198+
#' center are colored by the first, second and third and fourth element of
199+
#' this list respectively.
186200
#'
187201
#' @return A list with in the first element a numeric containing the dbh values
188202
#' for each tree point cloud, the second element the residuals on the circle
@@ -203,7 +217,9 @@ plot_circle_fit_pcs <- function(PCs_path, extension = ".txt",
203217
#' }
204218
plot_dbh_fit_pcs <- function(PCs_path, extension = ".txt", thresholdR2 = 0.001,
205219
slice_thickness = 0.06, dtm = NA, r = 5,
206-
OUT_path = "./") {
220+
OUT_path = "./",
221+
plotcolors = c("#000000", "#1c027a","#08aa7c",
222+
"#fac87f")) {
207223
file_paths <- list.files(PCs_path,
208224
pattern = paste("*", extension, sep = ""),
209225
full.names = TRUE
@@ -221,7 +237,8 @@ plot_dbh_fit_pcs <- function(PCs_path, extension = ".txt", thresholdR2 = 0.001,
221237
pc <- read_tree_pc(file_paths[i])
222238
out <- tryCatch(
223239
{
224-
dbh_pc(pc, thresholdR2, slice_thickness, dtm = dtm, r = r, plot = TRUE)
240+
dbh_pc(pc, thresholdR2, slice_thickness, dtm = dtm, r = r, plot = TRUE,
241+
plotcolors)
225242
},
226243
error = function(cond){
227244
message(cond)
@@ -275,6 +292,10 @@ plot_dbh_fit_pcs <- function(PCs_path, extension = ".txt", thresholdR2 = 0.001,
275292
#' \code{\link{tree_height_pc}}.
276293
#' @param r Numeric value (default=5) r, parameter of
277294
#' \code{\link{tree_height_pc}}. Only relevant if a dtm is provided.
295+
#' @param plotcolors list of three colors for plotting. Only relevant when plot
296+
#' = TRUE. The stem points above buttresses, stem points at breast height,
297+
#' fitted circle, the concave hull and the estimated center are colored by the
298+
#' first, second, third, fourth and fifth element of this list respectively.
278299
#'
279300
#' @return A list with in the first element a numeric containing the dab values
280301
#' for each tree point cloud, the second element the residuals on the circle
@@ -303,7 +324,9 @@ plot_dbh_fit_pcs <- function(PCs_path, extension = ".txt", thresholdR2 = 0.001,
303324
#' }
304325
plot_dab_fit_pcs <- function(PCs_path, extension = ".txt", OUT_path = "./",
305326
thresholdbuttress = 0.001, maxbuttressheight = 7,
306-
slice_thickness = 0.06, dtm = NA, r = 5) {
327+
slice_thickness = 0.06, dtm = NA, r = 5,
328+
plotcolors = c("#000000", "#808080", "#1c027a",
329+
"#08aa7c","#fac87f")) {
307330
file_paths <- list.files(PCs_path,
308331
pattern = paste("*", extension, sep = ""),
309332
full.names = TRUE
@@ -321,7 +344,7 @@ plot_dab_fit_pcs <- function(PCs_path, extension = ".txt", OUT_path = "./",
321344
print(paste("processing ", file_names[i]))
322345
pc <- read_tree_pc(file_paths[i])
323346
out <- dab_pc(pc, thresholdbuttress, maxbuttressheight, slice_thickness,
324-
dtm = dtm, r = r, plot = TRUE)
347+
dtm = dtm, r = r, plot = TRUE, plotcolors)
325348
filename <- paste(OUT_path, "dab_", strsplit(file_names[i], extension)[[1]],
326349
"_", as.character(thresholdbuttress), "_",
327350
as.character(maxbuttressheight), ".jpeg",
@@ -385,6 +408,9 @@ plot_dab_fit_pcs <- function(PCs_path, extension = ".txt", OUT_path = "./",
385408
#' \code{\link{tree_height_pc}}.
386409
#' @param r Numeric value (default=5) r, parameter of
387410
#' \code{\link{tree_height_pc}}. Only relevant if a dtm is provided.
411+
#' @param plotcolors list of two colors for plotting. Only relevant when plot =
412+
#' TRUE. The crown and trunk are colored by the first and second element of
413+
#' this list respectively.
388414
#'
389415
#' @return Returns a list with the plots and individual plots saved in the
390416
#' output folder.
@@ -425,7 +451,8 @@ plot_crown_classification_pcs <- function(PCs_path, extension = ".txt",
425451
slice_thickness = 0.06,
426452
thresholdbuttress = 0.001,
427453
maxbuttressheight = 7,
428-
dtm = NA, r = 5) {
454+
dtm = NA, r = 5,
455+
plotcolors = c("#08aa7c","#fac87f")) {
429456
file_paths <- list.files(PCs_path,
430457
pattern = paste("*", extension, sep = ""),
431458
full.names = TRUE
@@ -441,7 +468,7 @@ plot_crown_classification_pcs <- function(PCs_path, extension = ".txt",
441468
out <- classify_crown_pc(
442469
pc, thresholdbranch, minheight, buttress,
443470
thresholdR2, slice_thickness, thresholdbuttress,
444-
maxbuttressheight, dtm = dtm, r = r , plot = TRUE
471+
maxbuttressheight, dtm = dtm, r = r , plot = TRUE, plotcolors
445472
)
446473
filename <- paste(OUT_path, "crown_",
447474
strsplit(file_names[i], extension)[[1]], "_",
@@ -515,6 +542,9 @@ plot_crown_classification_pcs <- function(PCs_path, extension = ".txt",
515542
#' \code{\link{tree_height_pc}}.
516543
#' @param r Numeric value (default=5) r, parameter of
517544
#' \code{\link{tree_height_pc}}. Only relevant if a dtm is provided.
545+
#' @param plotcolors list of two colors for plotting. Only relevant when plot =
546+
#' TRUE. The stem points and the concave hull are colored by the first and
547+
#' second element of this list respectively.
518548
#'
519549
#' @return A list with in the first element a numeric containing the projected
520550
#' area values for each tree point cloud. In the second element there is the
@@ -545,7 +575,8 @@ plot_pa_pcs <- function(PCs_path, extension = ".txt", OUT_path = "./",
545575
concavity = 2, crown = FALSE, thresholdbranch = 1.5,
546576
minheight = 1, buttress = FALSE, thresholdR2 = 0.001,
547577
slice_thickness = 0.06, thresholdbuttress = 0.001,
548-
maxbuttressheight = 7, dtm = NA, r = 5) {
578+
maxbuttressheight = 7, dtm = NA, r = 5,
579+
plotcolors = c("#000000","#08aa7c")) {
549580
file_paths <- list.files(PCs_path,
550581
pattern = paste("*", extension, sep = ""),
551582
full.names = TRUE
@@ -565,7 +596,8 @@ plot_pa_pcs <- function(PCs_path, extension = ".txt", OUT_path = "./",
565596
thresholdR2, slice_thickness,
566597
thresholdbuttress, maxbuttressheight, dtm = dtm, r = r, FALSE
567598
)
568-
out <- projected_area_pc(crown_pc$crownpoints, concavity, TRUE)
599+
out <- projected_area_pc(crown_pc$crownpoints, concavity, TRUE,
600+
plotcolors)
569601
plot_area <- out$plot +
570602
ggplot2::ggtitle(bquote(PCA == .(round(out$pa, 2)) ~ m^2))
571603
filename <- paste(OUT_path, "pca_", strsplit(
@@ -576,7 +608,7 @@ plot_pa_pcs <- function(PCs_path, extension = ".txt", OUT_path = "./",
576608
sep = ""
577609
)
578610
} else {
579-
out <- projected_area_pc(pc, concavity, TRUE)
611+
out <- projected_area_pc(pc, concavity, TRUE, plotcolors)
580612
plot_area <- out$plot
581613
filename <- paste(OUT_path, "pa_",
582614
strsplit(file_names[i], extension)[[1]], "_", as.character(concavity),
@@ -648,6 +680,7 @@ plot_pa_pcs <- function(PCs_path, extension = ".txt", OUT_path = "./",
648680
#' \code{\link{tree_height_pc}}.
649681
#' @param r Numeric value (default=5) r, parameter of
650682
#' \code{\link{tree_height_pc}}. Only relevant if a dtm is provided.
683+
#' @param plotcolor color for plotting 3D shape. Only relevant when plot = TRUE.
651684
#'
652685
#' @return a numeric containing the volume values for each tree point cloud.
653686
#' Figures are saved in the output folder.
@@ -677,7 +710,8 @@ plot_av_pcs <- function(PCs_path, extension = ".txt", OUT_path = "./",
677710
alpha = 1, crown = FALSE, thresholdbranch = 1.5,
678711
minheight = 1, buttress = FALSE, thresholdR2 = 0.001,
679712
slice_thickness = 0.06, thresholdbuttress = 0.001,
680-
maxbuttressheight = 7, dtm = NA, r = 5) {
713+
maxbuttressheight = 7, dtm = NA, r = 5,
714+
plotcolor = "#fac87f") {
681715
file_paths <- list.files(PCs_path,
682716
pattern = paste("*", extension, sep = ""),
683717
full.names = TRUE
@@ -703,7 +737,7 @@ plot_av_pcs <- function(PCs_path, extension = ".txt", OUT_path = "./",
703737
sep = ""
704738
)
705739
} else {
706-
out <- alpha_volume_pc(pc, alpha, TRUE)
740+
out <- alpha_volume_pc(pc, alpha, TRUE, plotcolor)
707741
fig_name <- paste(OUT_path, "av_",
708742
strsplit(file_names[i], extension)[[1]], "_", as.character(alpha),
709743
".png",

R/summary_metrics.R

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@
5454
#' @param plot Logical (default=FALSE), indicates if summary figure for each
5555
#' tree point cloud is plotted. If an OUT_path is provided, the figures are
5656
#' saved in the OUT_path.
57-
#'
57+
#' @param plotcolors list of five colors for plotting. Only relevant when plot
58+
#' = TRUE. The stem points above buttresses, stem points at breast height,
59+
#' fitted circle, the concave hull and the estimated center are colored by the
60+
#' first, second, third, fourth and fifth element of this list respectively.
5861
#'
5962
#' @return The summary of the basic structural metrics for multiple tree point
6063
#' clouds as a data.frame. Includes the tree height, diameter at breast
@@ -87,7 +90,12 @@ summary_basic_pointcloud_metrics <- function(PCs_path, extension = ".txt",
8790
slice_thickness = 0.06,
8891
thresholdbuttress = 0.001,
8992
maxbuttressheight = 7,
90-
OUT_path = FALSE, plot = FALSE) {
93+
OUT_path = FALSE, plot = FALSE,
94+
plotcolors = c("#000000",
95+
"#808080",
96+
"#1c027a",
97+
"#08aa7c",
98+
"#fac87f")) {
9199
trees <- data.frame(
92100
"tree_id" = character(), "X_position" = double(),
93101
"Y_position" = double(), "tree_height_m" = double(),
@@ -123,13 +131,13 @@ summary_basic_pointcloud_metrics <- function(PCs_path, extension = ".txt",
123131
print(paste("processing ", filenames[i]))
124132
pc <- read_tree_pc(filepaths[i])
125133
pos <- tree_position_pc(pc)
126-
h_out <- tree_height_pc(pc, dtm, r, plot)
134+
h_out <- tree_height_pc(pc, dtm, r, plot, plotcolors = plotcolors[c(1,4:5)])
127135
h <- h_out$h
128136
if (buttress) {
129137
dab_out <- tryCatch(
130138
{
131139
dab_pc(pc, thresholdbuttress, maxbuttressheight, slice_thickness,
132-
dtm, r, plot)
140+
dtm, r, plot, plotcolors)
133141
},
134142
error = function(cond){
135143
message(cond)
@@ -142,7 +150,8 @@ summary_basic_pointcloud_metrics <- function(PCs_path, extension = ".txt",
142150
} else {
143151
dbh_out <- tryCatch(
144152
{
145-
dbh_out <- dbh_pc(pc, thresholdR2, slice_thickness, dtm, r, plot)
153+
dbh_out <- dbh_pc(pc, thresholdR2, slice_thickness, dtm, r, plot,
154+
plotcolors = plotcolors[c(1,3:5)])
146155
},
147156
error = function(cond){
148157
message(cond)
@@ -158,7 +167,8 @@ summary_basic_pointcloud_metrics <- function(PCs_path, extension = ".txt",
158167
{
159168
classify_crown_pc(pc, thresholdbranch, minheight, buttress,
160169
thresholdR2, slice_thickness, thresholdbuttress,
161-
maxbuttressheight, dtm, r, plot)
170+
maxbuttressheight, dtm, r, plot,
171+
plotcolors = plotcolors[c(4:5)])
162172
},
163173
error = function(cond){
164174
message(paste(cond, "!crown classification not possible, will calculate tree area and volume", sep = ""))
@@ -173,7 +183,8 @@ summary_basic_pointcloud_metrics <- function(PCs_path, extension = ".txt",
173183
c("crownpoints",
174184
"trunkpoints"))
175185
}
176-
pa_out <- projected_area_pc(pc, concavity, plot)
186+
pa_out <- projected_area_pc(pc, concavity, plot,
187+
plotcolors = plotcolors[c(1,4)])
177188
av <- alpha_volume_pc(pc, alpha)
178189
if (plot) {
179190
pa <- pa_out$pa

man/alpha_volume_pc.Rd

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/classify_crown_pc.Rd

Lines changed: 12 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/dab_pc.Rd

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/dbh_pc.Rd

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)