@@ -83,6 +83,7 @@ StatProject <- ggplot2::ggproto("StatProject", ggplot2::Stat,
83
83
# ' or 3857 if \code{fromepsg} is not specified)
84
84
# ' @param fromprojection Long form of \code{fromepsg}, a CRS object created by \code{sp::CRS()}
85
85
# ' @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.
86
87
# ' @param ... Agruments passed on to the \code{geom_*} (e.g. \code{lwd}, \code{fill}, etc.)
87
88
# '
88
89
# ' @importFrom ggplot2 layer
@@ -119,7 +120,7 @@ StatProject <- ggplot2::ggproto("StatProject", ggplot2::Stat,
119
120
# '
120
121
geom_spatial <- function (data = NULL , mapping = NULL , show.legend = TRUE , inherit.aes = TRUE ,
121
122
position = " identity" , fromepsg = NULL , toepsg = NULL ,
122
- fromprojection = NULL , toprojection = NULL , ... ) {
123
+ fromprojection = NULL , toprojection = NULL , fillrule = ' winding ' , ... ) {
123
124
rgdal :: CRSargs(CRS(" +init=epsg:3857" )) # hack to load rgdal namespace
124
125
long <- NULL ; rm(long ); lat <- NULL ; rm(lat ) # hack for use of aes()
125
126
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.
141
142
# check type of input and return appropriate data, mapping, and geom
142
143
if (methods :: is(data , " SpatialPolygonsDataFrame" )) {
143
144
data @ data $ .id <- rownames(data @ data )
144
- data.fort <- suppressMessages(fortify_SpatialPolygons (data ))
145
+ data.fort <- suppressMessages(ggplot2 :: fortify (data ))
145
146
data <- suppressWarnings(merge(data.fort , data @ data , by.x = " id" , by.y = " .id" ))
146
147
if (is.null(mapping )) {
147
148
mapping <- ggplot2 :: aes()
148
149
}
149
150
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 ),
151
152
mapping [! (names(mapping ) %in% c(" colour" , " col" , " color" ))])
152
153
class(mapping ) <- " uneval"
153
- geom <- " polygon "
154
+ geom <- ggpolypath :: GeomPolypath
154
155
pathparams <- params [names(params )!= " fill" ]
155
156
params <- params [! (names(params ) %in% c(" colour" , " col" , " color" ))]
157
+ params $ rule <- fillrule
156
158
class(pathmapping ) <- " uneval"
157
159
if (any(names(pathparams ) %in% c(" col" , " color" , " colour" , " lty" , " linetype" , " size" )) ||
158
160
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.
188
190
mapping <- ggplot2 :: aes(x = x , y = y )
189
191
geom <- " point"
190
192
} else if (methods :: is(data , " SpatialPolygons" )) {
191
- data <- fortify_SpatialPolygons (data )
193
+ data <- fortify (data )
192
194
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
195
197
mapping_path <- mapping
196
198
pathparams <- params [names(params )!= " fill" ]
197
199
params <- params [! (names(params ) %in% c(" colour" , " col" , " color" ))]
200
+ params $ rule <- fillrule
198
201
pathmapping <- c(ggplot2 :: aes(group = group ), mapping )
199
202
class(pathmapping ) <- " uneval"
200
203
if (any(names(pathparams ) %in% c(" col" , " color" , " colour" , " lty" , " linetype" , " size" )) ||
0 commit comments