## ----include = FALSE---------------------------------------------------------- knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) knitr::opts_chunk$set( fig.width = 7, fig.height = 5, fig.align = "center" ) ## ----setup-------------------------------------------------------------------- library(sf) library(ggplot2) library(mapycusmaximus) theme_set(ggplot2::theme_minimal()) ## ----quick-start-------------------------------------------------------------- # Focus near a supplied geometry: use the centroid of the combined Melbourne polygon melbourne <- vic[vic$LGA_NAME == "MELBOURNE", ] vic_fisheye_demo <- sf_fisheye( vic, center = melbourne, # accept sf/sfc; centroid is used in working CRS r_in = 0.34, r_out = 0.60, zoom_factor = 15, squeeze_factor = 0.35, method = "expand", revolution = 0 ) ggplot() + geom_sf(data = vic_fisheye_demo, fill = "grey92", color = "white", linewidth = 0.2) + geom_sf(data = melbourne, fill = NA, color = "tomato", linewidth = 0.5) + ggtitle("FGC fisheye: Melbourne focus within Victoria") ## ----centers------------------------------------------------------------------ # Example: WGS84 center (Melbourne CBD), auto-project to a working CRS vic_cbd <- sf_fisheye( vic, center = c(144.9631, -37.8136), center_crs = "EPSG:4326", r_in = 0.30, r_out = 0.55, zoom_factor = 15, squeeze_factor = 0.30 ) ggplot(vic_cbd) + geom_sf(fill = "grey92", color = "white", linewidth = 0.2) + ggtitle("Center supplied as lon/lat (WGS84)") ## ----multi-layer-------------------------------------------------------------- centroids <- st_centroid(vic) vic$layer <- "polygon" centroids$layer <- "centroid" both <- rbind(vic[, c("LGA_NAME", "geometry", "layer")], centroids[, c("LGA_NAME", "geometry", "layer")]) both_fish <- sf_fisheye(both, center = melbourne, r_in = 0.34, r_out = 0.60, zoom_factor = 15, squeeze_factor = 0.35) ggplot() + geom_sf(data = both_fish[both_fish$layer == "polygon", ], fill = "grey92", color = "white", linewidth = 0.2) + geom_sf(data = both_fish[both_fish$layer == "centroid", ], color = "#2b6cb0", size = 0.6, alpha = 0.8) + ggtitle("Aligned overlays: transform layers together, plot separately") ## ----scale-radii, eval=FALSE-------------------------------------------------- # all_points <- sf_fisheye(all_points, center = melbourne, # zoom_factor = 1.8, squeeze_factor = 0.30) # scale_radii <- 1 - (((st_bbox(vic)["xmax"] - st_bbox(vic)["xmin"]) - # (st_bbox(all_points)["xmax"] - st_bbox(all_points)["xmin"])) / # (st_bbox(vic)["xmax"] - st_bbox(vic)["xmin"])) # vic_fisheye <- sf_fisheye(vic, center = melbourne, # r_in = 0.35 * scale_radii, # r_out = 0.50 * scale_radii, # zoom_factor = 1.8, squeeze_factor = 0.30) ## ----diagnostics-------------------------------------------------------------- grid <- create_test_grid(range = c(-1, 1), spacing = 0.1) warp <- fisheye_fgc(grid, r_in = 0.34, r_out = 0.5, zoom_factor = 1.3, squeeze_factor = 0.5) plot_fisheye_fgc(grid, warp, r_in = 0.34, r_out = 0.5)