@@ -83,6 +83,7 @@ StatProject <- ggplot2::ggproto("StatProject", ggplot2::Stat,
8383# ' or 3857 if \code{fromepsg} is not specified)
8484# ' @param fromprojection Long form of \code{fromepsg}, a CRS object created by \code{sp::CRS()}
8585# ' @param toprojection Long form of \code{toepsg}, a CRS object created by \code{sp::CRS()}
86+ # ' @param fillrule One of 'evenodd' or 'winding', if Spatial object is a polygon layer.
8687# ' @param ... Agruments passed on to the \code{geom_*} (e.g. \code{lwd}, \code{fill}, etc.)
8788# '
8889# ' @importFrom ggplot2 layer
@@ -119,7 +120,7 @@ StatProject <- ggplot2::ggproto("StatProject", ggplot2::Stat,
119120# '
120121geom_spatial <- function (data = NULL , mapping = NULL , show.legend = TRUE , inherit.aes = TRUE ,
121122 position = " identity" , fromepsg = NULL , toepsg = NULL ,
122- fromprojection = NULL , toprojection = NULL , ... ) {
123+ fromprojection = NULL , toprojection = NULL , fillrule = ' winding ' , ... ) {
123124 rgdal :: CRSargs(CRS(" +init=epsg:3857" )) # hack to load rgdal namespace
124125 long <- NULL ; rm(long ); lat <- NULL ; rm(lat ) # hack for use of aes()
125126 group <- NULL ; rm(group ); x <- NULL ; rm(x ); y <- NULL ; rm(y ); id <- NULL ; rm(id ) # hack for use of aes()
@@ -141,18 +142,19 @@ geom_spatial <- function(data=NULL, mapping = NULL, show.legend = TRUE, inherit.
141142 # check type of input and return appropriate data, mapping, and geom
142143 if (methods :: is(data , " SpatialPolygonsDataFrame" )) {
143144 data @ data $ .id <- rownames(data @ data )
144- data.fort <- suppressMessages(fortify_SpatialPolygons (data ))
145+ data.fort <- suppressMessages(ggplot2 :: fortify (data ))
145146 data <- suppressWarnings(merge(data.fort , data @ data , by.x = " id" , by.y = " .id" ))
146147 if (is.null(mapping )) {
147148 mapping <- ggplot2 :: aes()
148149 }
149150 pathmapping <- c(ggplot2 :: aes(x = long , y = lat , group = group ), mapping )
150- mapping <- c(ggplot2 :: aes(x = long , y = lat , group = id ),
151+ mapping <- c(ggplot2 :: aes(x = long , y = lat , group = group ),
151152 mapping [! (names(mapping ) %in% c(" colour" , " col" , " color" ))])
152153 class(mapping ) <- " uneval"
153- geom <- " polygon "
154+ geom <- ggpolypath :: GeomPolypath
154155 pathparams <- params [names(params )!= " fill" ]
155156 params <- params [! (names(params ) %in% c(" colour" , " col" , " color" ))]
157+ params $ rule <- fillrule
156158 class(pathmapping ) <- " uneval"
157159 if (any(names(pathparams ) %in% c(" col" , " color" , " colour" , " lty" , " linetype" , " size" )) ||
158160 any(names(pathmapping ) %in% c(" col" , " color" , " colour" , " lty" , " linetype" , " size" ))) {
@@ -188,13 +190,14 @@ geom_spatial <- function(data=NULL, mapping = NULL, show.legend = TRUE, inherit.
188190 mapping <- ggplot2 :: aes(x = x , y = y )
189191 geom <- " point"
190192 } else if (methods :: is(data , " SpatialPolygons" )) {
191- data <- fortify_SpatialPolygons (data )
193+ data <- fortify (data )
192194 if (! is.null(mapping )) warning(" Overriding default mapping for SpatialPolygons input" )
193- mapping <- ggplot2 :: aes(x = long , y = lat , group = id )
194- geom <- " polygon "
195+ mapping <- ggplot2 :: aes(x = long , y = lat , group = group )
196+ geom <- ggpolypath :: GeomPolypath
195197 mapping_path <- mapping
196198 pathparams <- params [names(params )!= " fill" ]
197199 params <- params [! (names(params ) %in% c(" colour" , " col" , " color" ))]
200+ params $ rule <- fillrule
198201 pathmapping <- c(ggplot2 :: aes(group = group ), mapping )
199202 class(pathmapping ) <- " uneval"
200203 if (any(names(pathparams ) %in% c(" col" , " color" , " colour" , " lty" , " linetype" , " size" )) ||
0 commit comments