-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
164 lines (137 loc) · 4.59 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
---
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%",
warning = FALSE,
message = FALSE
)
```
# geocn <a href="https://stscl.github.io/geocn/"><img src="man/figures/logo.png" align="right" height="139" alt="geocn website" /></a>
<!-- badges: start -->
[![CRAN](https://www.r-pkg.org/badges/version/geocn)](https://CRAN.R-project.org/package=geocn)
[![R-universe](https://stscl.r-universe.dev/badges/geocn)](https://stscl.r-universe.dev/geocn)
<!-- badges: end -->
The goal of **geocn** is to provide various commonly used spatial data related to Chinese regions in the R programming environment.
## Installation
- Install development binary version from [R-universe](https://stscl.r-universe.dev/geocn) with:
``` r
install.packages("geocn",
repos = c("https://stscl.r-universe.dev",
"https://cloud.r-project.org"),
dep = TRUE)
```
- Install development source version from [GitHub](https://github.com/stscl/geocn) with:
``` r
# install.packages("devtools")
devtools::install_github("stscl/geocn",
build_vignettes = TRUE,
dep = TRUE)
```
## Example
### Drawing a Map of China Using `ggplot2`
```{r map1,fig.width=9.5,fig.height=7.5,fig.dpi=120}
library(sf)
library(ggplot2)
library(cowplot)
library(geocn)
albers = load_cn_alberproj()
province = load_cn_province()
tenline = load_cn_tenline()
ocean = load_world_ocean()
lakes = load_world_lake()
coastline = load_world_coastline()
ggplot() +
geom_sf(data = ocean,fill="#BEE8FF",color="white",size=.1) +
geom_sf(data = coastline,color="#252525",size=.5) +
geom_sf(data = province,fill="white",size=.1,color="grey") +
geom_sf(data = lakes,fill="#BEE8FF",color="white",size=.1) +
geom_sf(data = tenline,size=.2,color="#9d98b7") +
ggfx::with_shadow(geom_sf(data = tenline,size=.2,color="#9d98b7") ,
sigma = 3,x_offset = -5,y_offset = -2) -> fig1
fig1 +
coord_sf(crs = albers,
ylim = c(1500000,6000000),
xlim = c(-3100000,2000000),
expand = FALSE) +
theme_bw() +
theme(plot.background = element_rect("grey97", fill = NA),
axis.text = element_blank(),
axis.ticks = element_blank(),
axis.title = element_blank()) -> china.main
fig1 +
coord_sf(crs = albers,
ylim = c(273000,2800000),
xlim = c(-350000,1350000)) +
theme_minimal() +
theme(
axis.text = element_blank(),
axis.ticks = element_blank(),
axis.title = element_blank(),
panel.grid = element_blank(),
panel.background = element_rect("#BEE8FF", color = NA),
panel.border = element_rect(fill=NA,
linetype = 1,
linewidth = 0.5),
plot.margin=unit(c(0,0,0,0),"cm")) -> china.ocean
ggdraw() +
draw_plot(china.main) +
draw_plot(china.ocean,x = .815, y = .015,
width = .13, height = .20) -> cnmap1
cnmap1
```
### Drawing a Map of China Using `tmap`
```{r ,fig.show='hide',fig.dpi=120}
library(sf)
library(tmap)
library(cowplot)
library(geocn)
albers = load_cn_alberproj()
cn_border = load_cn_border()
main_border = load_cn_landcoast()
tenline = load_cn_tenline()
province = load_cn_province()
tm_shape(main_border,
projection = albers) +
tm_lines(col = NA,lwd = 0.01) +
tm_shape(province) +
tm_fill(col = 'white',alpha = .5) +
tm_borders(col = 'grey40', lwd = 1.25) +
tm_shape(cn_border) +
tm_lines(col='#9d98b7',lwd = 2.5) +
tm_scale_bar(position = c(0.05,0.01),
width = 0.15,text.size = 1.05,
lwd = 2) +
tm_compass(position = c(0.05,0.9),
just = 'center',size = 1.5,
text.size = .65,show.labels = 1) +
tm_layout(legend.width = 0.75,
legend.text.size = 1,
legend.height = 1.75,
legend.position = c(0.045,0.075),
compass.type = "arrow",
fontfamily = "serif") -> cn_mainplot
tm_shape(tenline,
projection = albers) +
tm_lines(col=NA,lwd=0.01) +
tm_shape(province) +
tm_fill(col = 'white',alpha = .5) +
tm_borders(col = 'grey40', lwd = 1.25) +
tm_shape(cn_border) +
tm_lines(col='#9d98b7',lwd = 2.5) -> cn_miniplot
ggdraw() +
draw_plot(tmap_grob(cn_mainplot)) +
draw_plot(tmap_grob(cn_miniplot),
halign = 0.5,valign = 0.5,
height = 0.2,
x = 0.427,
y = 0.019) -> cnmap2
```
```{r map2,fig.width=7.25,fig.height=6,fig.dpi=120}
cnmap2
```