Skip to content

Commit

Permalink
- Added element_blank as an import from ggplot2
Browse files Browse the repository at this point in the history
- Improved modelHD documentation
- Update NAMESPACE
  • Loading branch information
ArthurBailly committed Oct 21, 2024
1 parent e9cf147 commit 6a47107
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 44 deletions.
7 changes: 7 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,23 @@ importFrom(data.table,tstrsplit)
importFrom(ggplot2,aes)
importFrom(ggplot2,arrow)
importFrom(ggplot2,coord_equal)
importFrom(ggplot2,element_blank)
importFrom(ggplot2,element_text)
importFrom(ggplot2,geom_point)
importFrom(ggplot2,geom_polygon)
importFrom(ggplot2,geom_segment)
importFrom(ggplot2,geom_smooth)
importFrom(ggplot2,geom_text)
importFrom(ggplot2,ggplot)
importFrom(ggplot2,ggtitle)
importFrom(ggplot2,labs)
importFrom(ggplot2,scale_color_manual)
importFrom(ggplot2,scale_shape_manual)
importFrom(ggplot2,scale_x_continuous)
importFrom(ggplot2,scale_y_continuous)
importFrom(ggplot2,theme)
importFrom(ggplot2,theme_minimal)
importFrom(ggplot2,unit)
importFrom(grDevices,terrain.colors)
importFrom(graphics,axis)
importFrom(graphics,grid)
Expand Down
4 changes: 2 additions & 2 deletions R/checkPlotCoord.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#'
#' @importFrom data.table data.table := setnames
#' @importFrom sf st_multipoint st_polygon st_sfc
#' @importFrom ggplot2 ggplot aes geom_point geom_segment geom_polygon geom_text scale_shape_manual scale_color_manual ggtitle theme_minimal theme coord_equal arrow unit
#' @importFrom ggplot2 ggplot aes geom_point geom_segment geom_polygon geom_text scale_shape_manual scale_color_manual ggtitle theme_minimal theme coord_equal arrow unit element_blank
#'
#' @author Arthur PERE, Maxime REJOU-MECHAIN, Arthur BAILLY
#'
Expand Down Expand Up @@ -78,7 +78,7 @@
#'
checkPlotCoord <- function(projCoord = NULL, longlat = NULL, relCoord, trustGPScorners, cornerID=NULL, maxDist = 15, rmOutliers = TRUE, drawPlot = TRUE, treeCoord = NULL) {

# parameters verification -------------------------------------------------
# Checking arguments -------------------------------------------------

if (is.null(longlat) && is.null(projCoord)) {
stop("Give at least one set of coordinates: longlat or projCoord")
Expand Down
2 changes: 1 addition & 1 deletion R/cutPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ if (getRversion() >= "2.15.1") {
))
}

#' Divides a plot in subplots
#' Divides one ore more plots into subplots
#'
#' This function divides a plot (or several plots) in subplots and returns the coordinates of the grid.
#' This function uses a procrust analysis to fit the rectangle you gave to the plot you have.
Expand Down
26 changes: 16 additions & 10 deletions R/modelHD.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
#' If the parameter model is null, the function return a plot with all the methods for
#' comparison, the function also returns a data.frame with:
#' - `method`: The method that had been used to construct the plot
#' - `color`: The color of the curve in the plot
#' - `RSE`: Residual Standard Error of the model
#' - `RSElog`: Residual Standard Error of the log model (`NULL` if other model)
#' - `Average_bias`: The average bias for the model
Expand All @@ -61,29 +60,36 @@
#' # Load a data set
#' data(NouraguesHD)
#'
#' # To model the height from a dataset
#' # Fit H-D models for the Nouragues dataset
#' \donttest{
#' HDmodel <- modelHD(D = NouraguesHD$D, H = NouraguesHD$H, drawGraph = TRUE)
#' }
#'
#' # If the method needed is known
#' HDmodel <- modelHD(D = NouraguesHD$D, H = NouraguesHD$H, method = "weibull", drawGraph = TRUE)
#' HDmodel <- modelHD(D = NouraguesHD$D, H = NouraguesHD$H, method = "log1", drawGraph = TRUE)
#' # For a chosen model
#' HDmodel <- modelHD(D = NouraguesHD$D, H = NouraguesHD$H,
#' method = "log2", drawGraph = TRUE)
#'
#' # Using weights
#' HDmodel <- modelHD(
#' D = NouraguesHD$D, H = NouraguesHD$H, method = "weibull", useWeight = TRUE,
#' drawGraph = TRUE
#' )
#' D = NouraguesHD$D, H = NouraguesHD$H,
#' method = "log2", useWeight = TRUE,
#' drawGraph = TRUE)
#'
#' # With multiple stands (plots)
#' HDmodel <- modelHD(
#' D = NouraguesHD$D, H = NouraguesHD$H,
#' method = "log2", useWeight = TRUE,
#' plot = NouraguesHD$plotId, drawGraph = TRUE)
#'
#' @importFrom graphics legend lines par plot grid axis
#' @importFrom stats SSmicmen lm median na.omit quantile rnorm sd predict coef
#' @importFrom utils data
#' @importFrom data.table data.table
#' @importFrom ggplot2 ggplot aes geom_point geom_smooth labs theme_minimal theme scale_x_continuous scale_y_continuous
#' @importFrom ggplot2 ggplot aes geom_point geom_smooth labs theme_minimal theme scale_x_continuous scale_y_continuous element_text

modelHD <- function(D, H, method = NULL, useWeight = FALSE, drawGraph = FALSE, plot = NULL) {

# parameters verification -------------------------------------------------
# Checking arguments -------------------------------------------------

# Check if there is enough data to compute an accurate model
nbNonNA <- sum(!is.na(H))
Expand Down
2 changes: 1 addition & 1 deletion man/cutPlot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 23 additions & 17 deletions man/modelHD.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions tests/testthat/test_00_modelHD.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require(data.table)
#require(data.table)

D <- NouraguesHD$D
H <- NouraguesHD$H
Expand Down Expand Up @@ -58,13 +58,13 @@ test_that("Without parameters", {
Res <- expect_message(modelHD(D, H, useWeight = TRUE), "build a HD model")

expect_is(Res, "data.frame")
expect_equal(ncol(Res), 5)
expect_equal(ncol(Res),4)

res <- "method color RSE RSElog Average_bias
log1 blue 4.305060 0.2231136 0.004227454
log2 green 4.222718 0.2215495 0.003121671
weibull orange 4.307951 NA 0.002823978
michaelis purple 4.294488 NA 0.014564152
res <- "method RSE RSElog Average_bias
log1 4.305060 0.2231136 0.004227454
log2 4.222718 0.2215495 0.003121671
weibull 4.307951 NA 0.002823978
michaelis 4.294488 NA 0.014564152
"


Expand Down
12 changes: 6 additions & 6 deletions tests/testthat/test_01_correctCoordGPS.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,26 @@ test_that("correct coord GPS in UTM", {
})

test_that("correct coord GPS error", {
expect_error(correctCoordGPS(), "Give at least one set of coordinates")
expect_error(suppressWarnings(correctCoordGPS()), "Give at least one set of coordinates")
expect_error(
correctCoordGPS(projCoord = projCoord, coordRel = coordRel, rangeX = 52, rangeY = 53,rmOutliers = FALSE),
suppressWarnings(correctCoordGPS(projCoord = projCoord, coordRel = coordRel, rangeX = 52, rangeY = 53,rmOutliers = FALSE)),
"must be of length 2"
)
expect_error(
correctCoordGPS(projCoord = projCoord, coordRel = coordRel, rangeX = c(0, 100), rangeY = c(0, 100), maxDist = c(15, 0),rmOutliers = FALSE),
suppressWarnings(correctCoordGPS(projCoord = projCoord, coordRel = coordRel, rangeX = c(0, 100), rangeY = c(0, 100), maxDist = c(15, 0),rmOutliers = FALSE)),
"Your argument maxDist must be of length 1"
)
expect_error(
correctCoordGPS(projCoord = projCoord, coordRel = coordRel, rangeX = c(0, 40), rangeY = c(0, 40),rmOutliers = FALSE),
suppressWarnings(correctCoordGPS(projCoord = projCoord, coordRel = coordRel, rangeX = c(0, 40), rangeY = c(0, 40),rmOutliers = FALSE)),
"coordRel must be inside the X and Y ranges"
)
expect_error(
correctCoordGPS(projCoord = projCoord, coordRel = rbind(coordRel, c(40, 40)), rangeX = c(0, 100), rangeY = c(0, 100),rmOutliers = FALSE),
suppressWarnings(correctCoordGPS(projCoord = projCoord, coordRel = rbind(coordRel, c(40, 40)), rangeX = c(0, 100), rangeY = c(0, 100),rmOutliers = FALSE)),
"same dimension"
)
skip_if_not_installed("proj4")
expect_error(
correctCoordGPS(longlat = c(15, 12), projCoord = projCoord,rmOutliers = FALSE),
suppressWarnings(correctCoordGPS(longlat = c(15, 12), projCoord = projCoord,rmOutliers = FALSE)),
"Give only one set of coordinates"
)
})
Expand Down

0 comments on commit 6a47107

Please sign in to comment.