-
Notifications
You must be signed in to change notification settings - Fork 2
/
README.Rmd
227 lines (149 loc) · 6.7 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
suppressPackageStartupMessages({
library(dplyr)
library(purrr)
library(svgpatternusgs)
})
```
```{r echo = FALSE, eval = FALSE}
# pkgdown::build_site(override = list(destination = "../coolbutuseless.github.io/package/svgpatternusgs"))
```
# svgpatternusgs <img src="man/figures/logo.svg" align="right" height=230/>
<!-- badges: start -->
![](http://img.shields.io/badge/cool-useless-green.svg)
![](http://img.shields.io/badge/mini-verse-blue.svg)
<!-- badges: end -->
`svgpatternusgs` provides SVG patterns from the [United States Geological Survey (USGS)](usgs.gov).
For online documentation, see the [svgpatternusgs pkgdown website](https://coolbutuseless.github.io/package/svgpatternusgs/index.html).
The USGS provides a large array of reference styles for geologic linework and map symbology.
* [USGS website for Geological Map Symbols](https://ngmdb.usgs.gov/fgdc_gds/geolsymstd/download.php)
* The raw data for this package was sourced from [davenquinn's github version](https://github.com/davenquinn/geologic-patterns)
## An example of the patterns provided
This is a screenshot of the original documentation which comes with these patterns
from the USGS
<img src="man/figures/USGS-sample.png" />
This list of all codes which have a pattern in this package:
```{r}
svgpatternusgs::all_usgs_codes
```
## What's in the box?
* Functions for accessing the SVG for all the provided USGS codes
* SVG pattern are supplied as `minisvg::SVGPattern` objects.
* Functions for encoding/decoding a pattern specification from a hex colour.
## To Do
The original SVG sources for this were OK but not perfect. I've patched some issues, but there
are still quite a few occasions where gaps and tears appear in patterns.
These errors don't appear to be systematic, so I think it will require some labour-intensive manual
corrections to individual patterns.
## Installation
You can install from [github](https://github.com/coolbutuseless/svgpatternusgs) with:
``` r
# install.packages("devtools")
devtools::install_github("coolbutuseless/lofi") # Colour encoding
devtools::install_github("coolbutuseless/minisvg") # SVG support
devtools::install_github("coolbutuseless/svgpatternusgs") # This package
```
## Create and show a pattern
```{r}
pattern <- create_usgs_pattern(usgs_code = 605, spacing = 50)
# pattern$show()
pattern$save_full_svg("man/figures/usgs-605.svg", width=400, height = 100)
```
<img src="man/figures/usgs-605.svg" />
### Multiple patterns
```{r eval=TRUE}
pattern_list <- svgpatternusgs::all_usgs_codes[41:72] %>%
purrr::map(create_usgs_pattern, spacing = 200)
patterns <- minisvg::SVGPatternList_to_svg(pattern_list, width=200, height=100, ncol = 4)
patterns$save("man/figures/usgs-sample.svg")
```
<img src="man/figures/usgs-sample.svg" />
## Using the pattern in a `minisvg` SVG document
```{r}
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Building an SVG logo with an animated stripe
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
library(minisvg)
doc <- minisvg::svg_doc(width = 400, height = 200)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Create a simple pattern using the `svgpatternsimple` package
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
geopattern1 <- svgpatternusgs::create_usgs_pattern(usgs_code = 601, spacing = 200)
geopattern2 <- svgpatternusgs::create_usgs_pattern(usgs_code = 655, spacing = 200)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Add the pattern to the documents list of definitions
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
doc$defs(geopattern1, geopattern2)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Create shapes filled with the patterns and add to doc
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
rect <- stag$rect(x='10%', y='10%', width='50%', height='50%', stroke = 'black',
fill=geopattern1)
circle <- stag$circle(cx = "75%", cy="60%", r="45%", stroke = 'black',
fill=geopattern2)
doc$append(rect, circle)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# output
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# doc$show()
doc$save("man/figures/README-example-rect.svg")
```
```{r echo=FALSE, results='asis'}
cat(
"<pre>",
"<details><summary style='color: #4169E1;'> Show/hide SVG text </summary>",
htmltools::htmlEscape(as.character(doc)),
"</details>",
"</pre>", sep='')
```
<img src = "man/figures/README-example-rect.svg">
## Creating the logo for this package
```{r}
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Building an SVG logo with an animated stripe
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
library(minisvg)
logo <- minisvg::svg_doc(width = 200, height = 200)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Create a simple pattern using the `svgpatternsimple` package
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
geopattern <- svgpatternusgs::create_usgs_pattern(usgs_code = 655, spacing = 200)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Add the pattern to the documents list of definitions
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
logo$defs(geopattern)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Create a hexagon filled with this pattern, and add it to the document
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
len <- 100
angles <- (seq(0, 360, 60) + 90) * pi/180
xs <- round(len * cos(angles) + 100, 2)
ys <- round(len * sin(angles) + 100, 2)
hex <- stag$polygon(id = 'hex', xs = xs, ys = ys)
hex$update(stroke = '#c0c0c0', fill = geopattern)
logo$append(hex)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# output
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# logo$show()
logo$save("man/figures/logo.svg")
```
```{r echo=FALSE, results='asis'}
cat(
"<pre>",
"<details><summary style='color: #4169E1;'> Show/hide SVG text </summary>",
htmltools::htmlEscape(as.character(logo)),
"</details>",
"</pre>", sep='')
```
<img src = "man/figures/logo.svg">