From c8dc452691cb1fbfa3db475ac39b08df5d4ad6e7 Mon Sep 17 00:00:00 2001 From: Ann-KristinKreutzmann Date: Sat, 21 Oct 2023 21:22:13 +0200 Subject: [PATCH] change plot function --- NAMESPACE | 5 +---- R/load_shape.R | 4 ++-- R/map_plot.R | 27 ++++++++++++++------------- man/load_shapeaustria.Rd | 4 ++-- man/map_plot.Rd | 20 +++++++++----------- 5 files changed, 28 insertions(+), 32 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 56a9d625..5d71aa64 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -143,13 +143,11 @@ importFrom(ggplot2,coord_fixed) importFrom(ggplot2,coord_flip) importFrom(ggplot2,element_blank) importFrom(ggplot2,facet_wrap) -importFrom(ggplot2,fortify) importFrom(ggplot2,geom_abline) importFrom(ggplot2,geom_boxplot) importFrom(ggplot2,geom_density) importFrom(ggplot2,geom_line) importFrom(ggplot2,geom_point) -importFrom(ggplot2,geom_polygon) importFrom(ggplot2,geom_qq) importFrom(ggplot2,geom_segment) importFrom(ggplot2,geom_sf) @@ -158,11 +156,9 @@ importFrom(ggplot2,geom_text) importFrom(ggplot2,geom_vline) importFrom(ggplot2,ggplot) importFrom(ggplot2,ggtitle) -importFrom(ggplot2,guides) importFrom(ggplot2,labs) importFrom(ggplot2,qplot) importFrom(ggplot2,scale_color_manual) -importFrom(ggplot2,scale_colour_gradient) importFrom(ggplot2,scale_fill_gradient) importFrom(ggplot2,scale_fill_manual) importFrom(ggplot2,scale_linetype_discrete) @@ -207,6 +203,7 @@ importFrom(parallelMap,parallelLibrary) importFrom(parallelMap,parallelStop) importFrom(readODS,write_ods) importFrom(reshape2,melt) +importFrom(rlang,.data) importFrom(spdep,geary.test) importFrom(spdep,mat2listw) importFrom(spdep,moran.test) diff --git a/R/load_shape.R b/R/load_shape.R index 19d2d514..94ecb269 100644 --- a/R/load_shape.R +++ b/R/load_shape.R @@ -1,8 +1,8 @@ #' Loading the Shape File for Austrian Districts #' -#' The function simplifies to load the shape file for austrian districts. +#' The function simplifies to load the shape file for Austrian districts. #' -#' @return A shape file of class \code{SpatialPolygonsDataFrame}. +#' @return A shape file of class \code{"sf", "data.frame"}. #' @details The shape file contains the borders of Austrian districts. Thus, it #' can be used for the visualization of estimation results for Austrian #' districts. diff --git a/R/map_plot.R b/R/map_plot.R index c27ef4dc..d9112867 100644 --- a/R/map_plot.R +++ b/R/map_plot.R @@ -3,8 +3,8 @@ #' Function \code{map_plot} creates spatial visualizations of the estimates #' obtained by small area estimation methods. #' -#' @param object an object of type \code{saeTrafo}, containing the estimates to -#' be visualized. +#' @param object an object of type emdi, containing the estimates to be +#' visualized. #' @param indicator optional character vector that selects which indicators #' shall be returned: (i) all calculated indicators ("all"); #' (ii) each indicator name: "Mean", "Quantile_10", "Quantile_25", "Median", @@ -21,8 +21,8 @@ #' Defaults to \code{FALSE}. #' @param CV optional logical. If \code{TRUE}, the CV is also visualized. #' Defaults to \code{FALSE}. -#' @param map_obj an \code{SpatialPolygonsDataFrame} object as defined by the -#' \pkg{sp} package on which the data should be visualized. +#' @param map_obj an \code{"sf", "data.frame"} object as defined by the +#' \pkg{sf} package on which the data should be visualized. #' @param map_dom_id a character string containing the name of a variable in #' \code{map_obj} that indicates the domains. #' @param map_tab a \code{data.frame} object with two columns that match the @@ -31,19 +31,20 @@ #' in both objects differ. #' @param color a \code{vector} of length 2 defining the lowest and highest #' color in the plots. -#' @param scale_points a numeric vector of length two. This +#' @param scale_points a structure defining the lowest and the highest +#' value of the colorscale. If a numeric vector of length two is given, this #' scale will be used for every plot. -#' @param guide character passed to \code{scale_fill_gradient} from -#' \pkg{ggplot2}. Possible values are "none", "colourbar", and "legend". -#' Defaults to "colourbar". +#' @param guide character passed to +#' \code{scale_colour_gradient} from \pkg{ggplot2}. +#' Possible values are "none", "colourbar", and "legend". #' @param return_data if set to \code{TRUE}, a fortified data frame including #' the map data as well as the chosen indicators is returned. Customized maps #' can easily be obtained from this data frame via the package \pkg{ggplot2}. #' Defaults to \code{FALSE}. -#' @return Creates the plots demanded and, if selected, a fortified data.frame +#' @return Creates the plots demanded, and, if selected, a fortified data.frame #' containing the mapdata and chosen indicators. -#' @seealso \code{\link[sf]{sf}}, \code{\link{NER_Trafo}}, -#' \code{\link{saeTrafoObject}} +#' @seealso \code{\link{direct}}, \code{\link{ebp}}, \code{\link{fh}}, +#' \code{\link{emdiObject}}, \code{\link[sf]{sf}} #' @examples #' \donttest{ #' data("eusilcA_pop") @@ -228,10 +229,10 @@ plot_real <- function(object, if (any(is.na(matcher))) { if (all(is.na(matcher))) { - stop(paste("Domain of saeTrafo object and Map object do not match.", + stop(paste("Domain of emdi object and Map object do not match.", "Try using map_tab")) } else { - warnings(paste("Not all Domains of saeTrafo object and Map object", + warnings(paste("Not all Domains of emdi object and Map object", "could be matched. Try using map_tab")) } } diff --git a/man/load_shapeaustria.Rd b/man/load_shapeaustria.Rd index 5ce364c2..95201d4e 100644 --- a/man/load_shapeaustria.Rd +++ b/man/load_shapeaustria.Rd @@ -7,10 +7,10 @@ load_shapeaustria() } \value{ -A shape file of class \code{SpatialPolygonsDataFrame}. +A shape file of class \code{"sf", "data.frame"}. } \description{ -The function simplifies to load the shape file for austrian districts. +The function simplifies to load the shape file for Austrian districts. } \details{ The shape file contains the borders of Austrian districts. Thus, it diff --git a/man/map_plot.Rd b/man/map_plot.Rd index ddf73164..9172ea83 100644 --- a/man/map_plot.Rd +++ b/man/map_plot.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/map_plot.R \name{map_plot} \alias{map_plot} -\title{Visualizes Regional Disaggregated Estimates on a Map} +\title{Visualizes regional disaggregated estimates on a map} \usage{ map_plot( object, @@ -41,8 +41,8 @@ Defaults to \code{FALSE}.} \item{CV}{optional logical. If \code{TRUE}, the CV is also visualized. Defaults to \code{FALSE}.} -\item{map_obj}{an \code{SpatialPolygonsDataFrame} object as defined by the -\pkg{sp} package on which the data should be visualized.} +\item{map_obj}{an \code{"sf", "data.frame"} object as defined by the +\pkg{sf} package on which the data should be visualized.} \item{map_dom_id}{a character string containing the name of a variable in \code{map_obj} that indicates the domains.} @@ -74,7 +74,7 @@ containing the mapdata and chosen indicators. } \description{ Function \code{map_plot} creates spatial visualizations of the estimates -obtained by small area estimation methods or direct estimation. +obtained by small area estimation methods. } \examples{ \donttest{ @@ -106,13 +106,11 @@ map_plot( # file # First find the right order -dom_ord <- match(shape_austria_dis@data$PB, emdi_model$ind$Domain) +dom_ord <- match(shape_austria_dis$PB, emdi_model$ind$Domain) -# Create the mapping table based on the order obtained above -map_tab <- data.frame( - pop_data_id = emdi_model$ind$Domain[dom_ord], - shape_id = shape_austria_dis@data$BKZ -) +#Create the mapping table based on the order obtained above +map_tab <- data.frame(pop_data_id = emdi_model$ind$Domain[dom_ord], + shape_id = shape_austria_dis$BKZ) # Create map plot for mean indicator - point and CV estimates but no MSE # using the numerical domain identifiers of the shape file @@ -126,5 +124,5 @@ map_plot( } \seealso{ \code{\link{direct}}, \code{\link{ebp}}, \code{\link{fh}}, -\code{\link{emdiObject}}, \code{\link[maptools]{readShapePoly}} +\code{\link{emdiObject}}, \code{\link[sf]{sf}} }