@@ -158,8 +158,10 @@ ggframe <- function(n = 1e4, color = "black", fill = NA, lwd = 1, ...) {
158
158
prim.l1 <- seq(0 , 180 , length = n / 2 )
159
159
prim.l2 <- seq(- 180 , 0 , length = n / 2 )
160
160
prim.long <- c(prim.l1 , prim.l2 )
161
+
162
+ prim_df <- data.frame (prim.long , prim.lat )
161
163
162
- geom_polygon(aes(x = prim.long , y = prim.lat ), color = color , fill = fill , lwd = lwd , ... )
164
+ geom_polygon(aes(x = prim.long , y = prim.lat ), data = prim_df , color = color , fill = fill , lwd = lwd , ... , inherit.aes = FALSE )
163
165
}
164
166
165
167
ggstereo_grid <- function (d = 10 , rot = 0 , ... ) {
@@ -188,12 +190,17 @@ ggstereo_grid <- function(d = 10, rot = 0, ...) {
188
190
zp_ggl <- ggl(zp )
189
191
190
192
191
- geom_path(data = dplyr :: bind_rows(sm_ggl , gc_ggl , zp_ggl ), mapping = aes(x , y , group = group ), ... )
193
+ geom_path(data = dplyr :: bind_rows(sm_ggl , gc_ggl , zp_ggl ), mapping = aes(x , y , group = group ), ... , inherit.aes = FALSE )
192
194
}
193
195
194
196
195
197
# ' Stereonet using ggplot
196
198
# '
199
+ # ' @param data Default dataset to use for plot. If not already a data.frame,
200
+ # ' will be converted to one by [ggplot2::fortify()]. If not specified, must be
201
+ # ' supplied in each layer added to the plot.
202
+ # ' @param mapping Default list of aesthetic mappings to use for plot. If not
203
+ # ' specified, must be supplied in each layer added to the plot.
197
204
# ' @param earea logical. Whether the projection is equal-area ("Schmidt net")
198
205
# ' (`TRUE`, the default), or equal-angle ("Wulff net") (`FALSE`).
199
206
# ' @param grid.spacing numeric. Grid spacing in degree
@@ -221,17 +228,25 @@ ggstereo_grid <- function(d = 10, rot = 0, ...) {
221
228
# ' ggstereo(earea = FALSE, centercross = TRUE) +
222
229
# ' ggplot2::geom_point(data = gg(test_data), ggplot2::aes(x = x, y = y))
223
230
# ' }
224
- ggstereo <- function (earea = TRUE , centercross = TRUE , grid = FALSE , grid.spacing = 10 , grid.rot = 0 , ... ) {
231
+ ggstereo <- function (data = NULL , mapping = aes(), earea = TRUE , centercross = TRUE , grid = FALSE , grid.spacing = 10 , grid.rot = 0 , ... ) {
225
232
# if(earea){
226
233
# crs = "+proj=aeqd +lat_0=90 +lon_0=0 +x_0=0 +y_0=0"
227
234
# } else {
228
235
# crs = "+proj=stere +lat_0=90 +lon_0=0 +x_0=0 +y_0=0"
229
236
# }
230
237
rlang :: check_installed(" mapproj" , reason = " to use `coord_map()`" )
231
238
232
- ggplot() +
233
- theme_void() +
234
- {
239
+ ggplot(data = data , mapping = mapping ) +
240
+ # theme_void() +
241
+ theme(
242
+ title = element_text(element_text(face = " bold" )),
243
+ panel.background = element_blank(),
244
+ panel.border = element_blank(),
245
+ axis.ticks = element_blank(),
246
+ axis.title = element_blank(),
247
+ axis.text = element_blank(),
248
+ legend.title = element_blank()
249
+ ) + {
235
250
if (grid ) {
236
251
ggstereo_grid(d = grid.spacing , rot = grid.rot , color = " lightgrey" , lwd = .25 )
237
252
}
@@ -240,9 +255,8 @@ ggstereo <- function(earea = TRUE, centercross = TRUE, grid = FALSE, grid.spacin
240
255
annotate(" point" , x = 0 , y = 90 , pch = as.numeric(centercross ) * 3 ) +
241
256
scale_y_continuous(limits = c(0 , 90 )) +
242
257
scale_x_continuous(limits = c(- 180 , 180 )) +
243
- coord_map(ifelse(earea , " azequalarea" , " stereographic" ), orientation = c(90 , 0 , 0 )) +
244
- # coord_sf(crs = crs, default_crs = crs) +
245
- labs(x = NULL , y = NULL )
258
+ coord_map(ifelse(earea , " azequalarea" , " stereographic" ), orientation = c(90 , 0 , 0 ))
259
+ # coord_sf(crs = crs, default_crs = crs)
246
260
}
247
261
248
262
ignore_unused_imports <- function () {
@@ -305,7 +319,7 @@ vmf_kerncontour <- function(u, hw = NULL, kernel_method = c("cross", "rot"), ngr
305
319
306
320
# ' Stereonet contouring using ggplot
307
321
# '
308
- # ' @param x data.frame containing
322
+ # ' @param data data.frame containing the orientation
309
323
# ' @param ngrid integer. Resolution of density calculation.
310
324
# ' @param hw numeric. Kernel bandwidth in degree.
311
325
# ' @param optimal_bw character. Calculates an optimal kernel bandwidth
348
362
349
363
# ' @rdname ggstereocontour
350
364
# ' @export
351
- geom_contour_stereo <- function (x , ngrid = 200 , hw = NULL , optimal_bw = c(" cross" , " rot" ), norm = FALSE , threshold = 0 , ... ) {
365
+ geom_contour_stereo <- function (data , ngrid = 200 , hw = NULL , optimal_bw = c(" cross" , " rot" ), norm = FALSE , threshold = 0 , ... ) {
352
366
Long <- Lat <- Density <- NULL
353
- xtot <- full_hem(x )
367
+ xtot <- full_hem(data )
354
368
355
369
dens <- vmf_kerncontour(xtot , hw = hw , kernel_method = optimal_bw , ngrid = ngrid )
356
370
res <- expand.grid(Lat = dens $ lat - 90 , Long = dens $ long - 180 )
@@ -359,15 +373,16 @@ geom_contour_stereo <- function(x, ngrid = 200, hw = NULL, optimal_bw = c("cross
359
373
res $ Density <- normalize(res $ Density )
360
374
}
361
375
res $ Density [res $ Density < = threshold ] <- NA
376
+
362
377
geom_contour(data = res , aes(x = - Long , y = Lat , z = Density ), ... )
363
378
}
364
379
365
380
366
381
# ' @rdname ggstereocontour
367
382
# ' @export
368
- geom_contourf_stereo <- function (x , ngrid = 200 , hw = NULL , optimal_bw = c(" cross" , " rot" ), norm = FALSE , smooth = FALSE , threshold = 0 , ... ) {
383
+ geom_contourf_stereo <- function (data , ngrid = 200 , hw = NULL , optimal_bw = c(" cross" , " rot" ), norm = FALSE , smooth = FALSE , threshold = 0 , ... ) {
369
384
Long <- Lat <- Density <- NULL
370
- xtot <- full_hem(x )
385
+ xtot <- full_hem(data )
371
386
372
387
dens <- vmf_kerncontour(xtot , hw = hw , kernel_method = optimal_bw , ngrid = ifelse(smooth , 3 * ngrid , ngrid ))
373
388
res <- expand.grid(Lat = dens $ lat - 90 , Long = dens $ long - 180 )
0 commit comments