Skip to content

Commit afc6c75

Browse files
committed
update
1 parent c6c002f commit afc6c75

File tree

4 files changed

+55
-17
lines changed

4 files changed

+55
-17
lines changed

R/gg_stereonet.R

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,10 @@ ggframe <- function(n = 1e4, color = "black", fill = NA, lwd = 1, ...) {
158158
prim.l1 <- seq(0, 180, length = n / 2)
159159
prim.l2 <- seq(-180, 0, length = n / 2)
160160
prim.long <- c(prim.l1, prim.l2)
161+
162+
prim_df <- data.frame(prim.long, prim.lat)
161163

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)
163165
}
164166

165167
ggstereo_grid <- function(d = 10, rot = 0, ...) {
@@ -188,12 +190,17 @@ ggstereo_grid <- function(d = 10, rot = 0, ...) {
188190
zp_ggl <- ggl(zp)
189191

190192

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)
192194
}
193195

194196

195197
#' Stereonet using ggplot
196198
#'
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.
197204
#' @param earea logical. Whether the projection is equal-area ("Schmidt net")
198205
#' (`TRUE`, the default), or equal-angle ("Wulff net") (`FALSE`).
199206
#' @param grid.spacing numeric. Grid spacing in degree
@@ -221,17 +228,25 @@ ggstereo_grid <- function(d = 10, rot = 0, ...) {
221228
#' ggstereo(earea = FALSE, centercross = TRUE) +
222229
#' ggplot2::geom_point(data = gg(test_data), ggplot2::aes(x = x, y = y))
223230
#' }
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, ...) {
225232
# if(earea){
226233
# crs = "+proj=aeqd +lat_0=90 +lon_0=0 +x_0=0 +y_0=0"
227234
# } else {
228235
# crs = "+proj=stere +lat_0=90 +lon_0=0 +x_0=0 +y_0=0"
229236
# }
230237
rlang::check_installed("mapproj", reason = "to use `coord_map()`")
231238

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+
) + {
235250
if (grid) {
236251
ggstereo_grid(d = grid.spacing, rot = grid.rot, color = "lightgrey", lwd = .25)
237252
}
@@ -240,9 +255,8 @@ ggstereo <- function(earea = TRUE, centercross = TRUE, grid = FALSE, grid.spacin
240255
annotate("point", x = 0, y = 90, pch = as.numeric(centercross) * 3) +
241256
scale_y_continuous(limits = c(0, 90)) +
242257
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)
246260
}
247261

248262
ignore_unused_imports <- function() {
@@ -305,7 +319,7 @@ vmf_kerncontour <- function(u, hw = NULL, kernel_method = c("cross", "rot"), ngr
305319

306320
#' Stereonet contouring using ggplot
307321
#'
308-
#' @param x data.frame containing
322+
#' @param data data.frame containing the orientation
309323
#' @param ngrid integer. Resolution of density calculation.
310324
#' @param hw numeric. Kernel bandwidth in degree.
311325
#' @param optimal_bw character. Calculates an optimal kernel bandwidth
@@ -348,9 +362,9 @@ NULL
348362

349363
#' @rdname ggstereocontour
350364
#' @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, ...) {
352366
Long <- Lat <- Density <- NULL
353-
xtot <- full_hem(x)
367+
xtot <- full_hem(data)
354368

355369
dens <- vmf_kerncontour(xtot, hw = hw, kernel_method = optimal_bw, ngrid = ngrid)
356370
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
359373
res$Density <- normalize(res$Density)
360374
}
361375
res$Density[res$Density <= threshold] <- NA
376+
362377
geom_contour(data = res, aes(x = -Long, y = Lat, z = Density), ...)
363378
}
364379

365380

366381
#' @rdname ggstereocontour
367382
#' @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, ...) {
369384
Long <- Lat <- Density <- NULL
370-
xtot <- full_hem(x)
385+
xtot <- full_hem(data)
371386

372387
dens <- vmf_kerncontour(xtot, hw = hw, kernel_method = optimal_bw, ngrid = ifelse(smooth, 3 * ngrid, ngrid))
373388
res <- expand.grid(Lat = dens$lat - 90, Long = dens$long - 180)

man/ggstereo.Rd

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/ggstereocontour.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vignettes/Intro.Rmd

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,17 @@ ggstereo() +
9292
```
9393

9494

95+
## Facets
96+
```{r density, message=FALSE,warning=FALSE}
97+
area_l <- LETTERS[sample.int(3, nrow(lines), replace = TRUE)]
98+
area_p <- LETTERS[sample.int(3, nrow(planes), replace = TRUE)]
99+
100+
lines_df <- gg(lines, area=area_l)
101+
planes_df <- ggl(planes, area = area_p)
102+
103+
ggstereo(data = lines_df, aes(x=x, y=y, color = area)) +
104+
geom_path(data = planes_df, aes(x=x, y=y, group = group), alpha = .25, color = 'grey') +
105+
geom_point() +
106+
facet_wrap(vars(area)) +
107+
labs(title = "Example data", color = NULL)
108+
```

0 commit comments

Comments
 (0)