Support for geological fill patterns
Got a new one for you @willgearty!...
We often use some kind of pattern fill for geological maps and sedimentary logs to indicate lithology. I wonder if making such an option available in deeptime could be useful for the community. Perhaps using something like the USGS swatches pack? I also found this package ggpattern which might provide a good starting place for how this could be implemented?
Cool idea, I'll look into at some point!
It looks like ggplot 3.5.0 now has greatly improved pattern support: https://www.tidyverse.org/blog/2024/02/ggplot2-3-5-0/#patterns-and-gradients
More resources: https://github.com/davenquinn/geologic-patterns/ https://blog.r-hub.io/2020/05/29/distribute-data/#data-outside-of-your-package https://docs.ropensci.org/piggyback/
Oh, I found this! https://github.com/coolbutuseless/svgpatternusgs Which you can then use like this: https://coolbutuseless.github.io/2019/10/10/introducing-devoutsvg-svg-graphics-output-device-with-pattern-fills/#u.s.-geological-survey-patterns-on-geom_sf-plots
That looks perfect @willgearty! Looks like it should be straight forward to offer support for mapping and logging!
I've added these patterns as data to the package, and I've also added some functions that allow you to add them individually to plots or use them as scales in ggplot plots. It's all described in the documentation and there is a nice walkthrough in this vignette: https://williamgearty.com/deeptime/dev/articles/geo.html.
Would you be able to play around with it and let me know what you think @LewisAJones? Thanks!
Hi @willgearty, this is looking pretty fantastic and it is great to see it up and running. I've had a play around with the function and it is working really nicely. The vignette helped to understand the differences between the functionality available and when you want to customise the patterns (I think I would have struggled in some places without this).
I was initially worried that there was some problem with the resolution of the patterns. On my viewer plot pane, the patterns appear of very poor resolution but on exporting this plot via ggsave or similar, there is no problem. Do you know why this is? I ask because I still know many users who save plots using the export option.
In deeptime, you have tables of stages, periods, etc available for international timescales. Would it be worth having a table of the patterns available, something like a three column dataframe with the ID of the pattern, the name of the pattern, and the grouping of the pattern (e.g. sedimentary)? This way users could look up what is available without having to go to external resources? Or perhaps even something similar to rphylopic::pick_phylopic, where you can search for a pattern based on a search phrase to see what is available? Maybe that is a bit overkill for this...
One thing I did notice, that I think is important to address, is that pattern IDs don't seem to always match their unique patterns. This seems to be restricted to cases where you have the same pattern, but the patterns have a different colour. For example:
library(ggplot2)
vals <- c("434-K", "434-C", "434-M", "434-R")
ggplot(mpg, aes(factor(cyl), fill = vals[factor(cyl)])) +
geom_bar() +
scale_fill_geopattern(name = NULL)
All that said, I think this is great functionality, already highly usable, and will be really helpful to many! Thanks for putting it together!
Thanks @LewisAJones, this was super helpful!
I've added a bit more documentation regarding pattern codes (including other resources for determining them). Unfortunately, the vast majority of the patterns don't have text definitions (100s to 500s), so I don't think a database would be useful to users (or easy to build). I've also tried to make it clearer in the docs and the vignette that the alternative codes are supported but fallback to the defaults (e.g., 101-M results in using 101-K). This is done to reduce the size of the internal data and the overall package.
I've also added a bit more documentation about graphics device support. Unfortunately, this is highly OS dependent (and unfortunately the RStudio defaults don't support patterns well). However, I've included information about a variety of options for both changing the RStudio default and otherwise saving files.
Finally, I fixed the bug that you (perhaps unknowingly) have displayed in your second example image: the functions now correctly handle patterns that are not exactly square.
All of this new functionality will hopefully be on CRAN soon!