deeptime icon indicating copy to clipboard operation
deeptime copied to clipboard

Support for geological fill patterns

Open LewisAJones opened this issue 1 year ago • 5 comments

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?

LewisAJones avatar Feb 20 '24 18:02 LewisAJones

Cool idea, I'll look into at some point!

willgearty avatar Feb 20 '24 20:02 willgearty

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

willgearty avatar Feb 29 '24 19:02 willgearty

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/

willgearty avatar Jun 03 '24 21:06 willgearty

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

willgearty avatar Jun 03 '24 21:06 willgearty

That looks perfect @willgearty! Looks like it should be straight forward to offer support for mapping and logging!

LewisAJones avatar Jun 04 '24 07:06 LewisAJones

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.

image

Would you be able to play around with it and let me know what you think @LewisAJones? Thanks!

willgearty avatar Jul 25 '24 14:07 willgearty

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.

image

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)

image

All that said, I think this is great functionality, already highly usable, and will be really helpful to many! Thanks for putting it together!

LewisAJones avatar Aug 02 '24 10:08 LewisAJones

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!

willgearty avatar Aug 05 '24 21:08 willgearty