-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathREADME.Rmd
98 lines (76 loc) · 2.36 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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
# dev = 'svg',
dev = 'png',
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# gg.layers
<!-- badges: start -->
[![R-CMD-check](https://github.com/rpkgs/gg.layers/workflows/R-CMD-check/badge.svg)](https://github.com/rpkgs/gg.layers/actions)
[![codecov](https://codecov.io/gh/rpkgs/gg.layers/branch/master/graph/badge.svg)](https://codecov.io/gh/rpkgs/gg.layers)
[![CRAN](http://www.r-pkg.org/badges/version/gg.layers)](https://cran.r-project.org/package=gg.layers)
<!-- badges: end -->
## Installation
You can install the development version of gg.layers from [GitHub](https://github.com/) with:
``` r
# install.packages("remotes")
remotes::install_github("rpkgs/gg.layers")
```
## Document
- <https://ggplot2-book.org/programming.html>
- <https://ggplot2-book.org/extensions.html>
## Example
### self-made colorbar
<https://stackoverflow.com/questions/68440366/how-can-i-add-triangles-to-a-ggplot2-colorbar-in-r-to-indicate-out-of-bound-valu>
```{r example}
library(gg.layers)
library(ggplot2)
library(rcolors)
brk <- c(-Inf, -1, 0, 1, 3, 6, 9, Inf)
nbrk <- length(brk) - 1
cols <- get_color(rcolors$amwg256, nbrk)
g <- make_colorbar(
at = brk, col = cols, height = 1,
tck = 0.4,
space = "right",
legend.text.location = c(0.3, 0.5),
legend.text.just = c(0.5, 0.5),
# legend.text = list(fontfamily = "Times", cex = 1.1),
hjust = 0.05
)
p <- ggplot(mtcars %>% subset(cyl == 4), aes(mpg, disp)) +
geom_point() +
facet_wrap(~cyl) +
theme(legend.position = "none")
p + g
```
### significant regions
```{r sign}
data("d_trendPerc")
d_mask <- mutate(d_trendPerc, mask = perc <= 0.99) # %>% as.data.frame()
# 1. geom_signPoint
ggplot(data = d_mask, aes(x, y)) +
geom_raster(aes(fill = perc)) +
geom_signPoint(aes(mask = !mask), fact = 2, shape = 4)
# 2. geom_signHatch
ggplot() +
geom_raster(data = d_trendPerc, aes(x, y, fill = perc)) +
# geom_sf(data = shp) +
geom_signHatch(data = d_mask, aes(x, y, mask = mask), color = "red")
# 3. stat_signPattern
ggplot() +
geom_raster(data = d_trendPerc, aes(x, y, fill = perc)) +
stat_signPattern(
data = d_mask, aes(x, y, mask = mask),
fill = "transparent", color = "red",
pattern_density = 0.02
)
```