Commit 7f74aab4 authored by Jean-Marie Lepioufle's avatar Jean-Marie Lepioufle
Browse files

related to l-moment

parent 0379f0cc
#' plot_lmrd
# Function adapted from the package lmom
# Draws an L-moment ratio diagram
#' plot_lmrd
#' @param x tbl_lmom data.frame
#' @param path path
#' @param name name
#' @param DESKTOP boolean
#' @param width_mm width_mm
#' @param height_mm height_mm
#' @keywords basicr
#' @export
#' @examples
#' \dontrun{
#' plot_lmrd()
#' }
plot_lmrd<-function(x, path=tempdir(),name=NULL,DESKTOP=TRUE,width_mm=200,height_mm=200) {
if (inherits(x,"tbl_lmom")) {
#start plot
if (!(DESKTOP)) {
if(is.null(name)) {
filename <- normalizePath(file.path(path,paste0("lmrd.tiff")),mustWork = FALSE)
} else filename <-normalizePath(file.path(path,paste0("lmrd_",name,".tiff")),mustWork = FALSE)
grDevices::tiff(filename = filename, width = width_mm, height = height_mm,
units = "mm", pointsize = 12,
compression = "lzw",
bg = "transparent", res = 300)
} else grDevices::dev.new()
path <- try(normalizePath(file.path(.libPaths()[1],"basicr","data","lmrd_n_param_distrib.rda"),mustWork=TRUE))
load(path)
lmrd_distrib <- get("lmrd_n_param_distrib",envir=environment())
lmrd_3 <- lmrd_distrib %>% dplyr::filter(nb_par==3)
lmrd_2 <- lmrd_distrib %>% dplyr::filter(nb_par==2)
x_min <- min(0,x$t_3,na.rm=TRUE)
x_max <- max(0.6,x$t_3,na.rm=TRUE)
y_min <- min(0,x$t_4,na.rm=TRUE)
y_max <- max(0.4,x$t_4,na.rm=TRUE)
# plot
p <- ggplot2::ggplot() +
ggplot2::geom_line( data=lmrd_3, ggplot2::aes(x=t_3,y=t_4,group=distribution,linetype=distribution)) +
ggplot2::geom_point( data=lmrd_2, ggplot2::aes(x=t_3,y=t_4,group=distribution,shape=distribution),size=2) +
# ggplot2::scale_size_continuous(guide = FALSE) +
ggplot2::scale_shape_discrete(name ="2-par distribution") +
ggplot2::scale_linetype_discrete(name ="3-par distribution") +
ggplot2::geom_point( data=x, ggplot2::aes(x=t_3,y=t_4,colour=ID),size=2,shape=8) +
ggplot2::labs(x = expression(italic(L) * "-skewness"),y = expression(italic(L) * "-kurtosis")) +
ggplot2::xlim(x_min,x_max) +
ggplot2::ylim(y_min,y_max)
print(p)
if (!(DESKTOP)) {
grDevices::dev.off()
return(filename)
} else {
return(TRUE)
}
} else stop("x as 'tbl_lmom' object")
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lmrd_n_param_distrib.R
\docType{data}
\name{lmrd_n_param_distrib}
\alias{lmrd_n_param_distrib}
\title{lmrd_n_param_distrib}
\format{A rda file}
\source{
https://cran.r-project.org/web/packages/lmom/
}
\description{
lmrd_n_param_distrib provides L-skewness and L-kurtosis values of key 2-par and 3-par distributions
}
\references{
J. R. M. Hosking
}
\keyword{basicr}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment