https://github.com/mdsumner/freegeomsf
Free 'geom_sf' from its Aspect Ratio Shackles
https://github.com/mdsumner/freegeomsf
Last synced: 12 months ago
JSON representation
Free 'geom_sf' from its Aspect Ratio Shackles
- Host: GitHub
- URL: https://github.com/mdsumner/freegeomsf
- Owner: mdsumner
- License: other
- Created: 2023-05-27T09:18:40.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-05-27T09:25:26.000Z (about 3 years ago)
- Last Synced: 2025-03-26T09:22:22.362Z (about 1 year ago)
- Language: R
- Size: 273 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
---
output: github_document
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# freegeomsf
The goal of freegeomsf is to modify sf data in order to simulate the support for free scales in facted ggplots (as if we did `+ facet_wrap(~a, scales = "free"))`).
Currently we only support a single option, to rescale every geom to its own unit square. Other variants are possible (x vs y, grouped scales, etc).
## Installation
You can install the development version of freegeomsf like so:
``` r
# install.packages("pak")
pak::pak("mdsumner/freegeomsf")
```
## Example
This is a basic example which shows how to plot some polygons of a New Zealand
data set separately as facets.
```{r example}
library(freegeomsf)
library(ggplot2)
ggplot(freegeomsf(sfx[1:12, ])) + geom_sf() + facet_wrap(~a) +
theme(axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank(),
axis.title.y=element_blank(),
axis.text.y=element_blank(),
axis.ticks.y=element_blank())
```
This would be a completely pointless plot if we faceted with the original data
because we can't control the scales in the usual ways.
(Sometimes we want to see what polygons look like relative to other polygons, other options IYI involve cowplot or patchwork but this approach was sufficient here).
A less verbose way to remove axis labels wbg.
Note that the axes are unrealistic here because we can only *simulate* free scales by modifying the data. This kind of plot is essential for some work, but it would be nice to keep the reality of the axes too but we can't.
(We could of course decompose the data and use geom_polygon, but there's a lot of details to worry about and this was easier just to get on with the work required).
## Motivation
This was motivated by the need for a simple plot requirement so we could see the relationship between polygons in detail. Sometimes you can't tell what polygons are holes in what other polygons, and this is obviously a useful thing to be able to indicate in environmental protection and management scenarios.
The idea was originally noted here: https://gist.github.com/mdsumner/7b354f73b47ccb67861ff0363cdbb3d3
In other aspirations this might become a set of helpers for shift, scale, rotate for geometries that aren't just one format.
## Code of Conduct
Please note that the freegeomsf project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/1/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.