0% found this document useful (0 votes)
112 views26 pages

Drawing Beautiful Maps Programmatically With R, SF and Ggplot2 - Part 3 - Layouts

This document discusses different approaches for arranging maps in R for clear visual communication. It presents two main solutions for combining sub-maps: using ggplot2 grobs or the cowplot package. Examples show arranging plots within the plot region using grobs and annotation_custom, or anywhere on the graphic device using cowplot's ggdraw and draw_plot functions. The document also demonstrates arranging multiple maps side-by-side on a grid, allowing reproducible positioning of individual maps. The goal is to help convey information aesthetically and effectively through map layouts.

Uploaded by

Rafael Monteiro
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
112 views26 pages

Drawing Beautiful Maps Programmatically With R, SF and Ggplot2 - Part 3 - Layouts

This document discusses different approaches for arranging maps in R for clear visual communication. It presents two main solutions for combining sub-maps: using ggplot2 grobs or the cowplot package. Examples show arranging plots within the plot region using grobs and annotation_custom, or anywhere on the graphic device using cowplot's ggdraw and draw_plot functions. The document also demonstrates arranging multiple maps side-by-side on a grid, allowing reproducible positioning of individual maps. The goal is to help convey information aesthetically and effectively through map layouts.

Uploaded by

Rafael Monteiro
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

23/10/2020 Drawing beautiful maps programmatically with R, sf and ggplot2 — Part 3: Layouts

r-spatial Events Projects Book About

Drawing beautiful maps programmatically


with R, sf and ggplot2 — Part 3: Layouts
Oct 25, 2018 • Mel Moreno and Mathieu Basille

view raw Rmd

EDIT: Following a suggestion from Adriano Fantini and code from Andy South, we replaced rworlmap
by rnaturalearth . We also largely edited the text.

This tutorial is the third part in a series of three:

General concepts illustrated with the world map


Adding additional layers: an example with points and polygons
Positioning and layout for complex maps (this document)

After the presentation of basic map concepts, and the flexible approach in layers implemented in
ggplot2 , this part illustrates how to achieve complex layouts, for instance with map insets, or several
maps combined. Depending on the visual information that needs to be displayed, maps and their
corresponding data might need to be arranged to create easy to read graphical representations. This
tutorial will provide different approaches to arranges maps in the plot, in order to make the information
portrayed more aesthetically appealing, and most importantly, convey the information better.

Getting started

https://www.r-spatial.org/r/2018/10/25/ggplot2-sf-3.html 1/26
23/10/2020 Drawing beautiful maps programmatically with R, sf and ggplot2 — Part 3: Layouts

Many R packages are available from CRAN, the Comprehensive R Archive Network, which is the
primary repository of R packages. The full list of packages necessary for this series of tutorials can be
installed with:

install.packages(c("cowplot", "googleway", "ggplot2", "ggrepel",


"ggspatial", "libwgeom", "sf", "rnaturalearth", "rnaturalearthdata"))

We start by loading the basic packages necessary for all maps, i.e. ggplot2 and sf . We also suggest
to use the classic dark-on-light theme for ggplot2 ( theme_bw ), which is more appropriate for maps:

library("ggplot2")
theme_set(theme_bw())
library("sf")

The package rnaturalearth provides a map of countries of the entire world. Using ne_counties to
pull the country data and,choose the scale. For returnclass , the setting can for be ‘sf’ and/or ‘sp’:

library("rnaturalearth")
library("rnaturalearthdata")

world <- ne_countries(scale='medium',returnclass = 'sf')


class(world)

## [1] "sf"
## [1] "data.frame"

General concepts
There are 2 solutions to combine sub-maps:

https://www.r-spatial.org/r/2018/10/25/ggplot2-sf-3.html 2/26
23/10/2020 Drawing beautiful maps programmatically with R, sf and ggplot2 — Part 3: Layouts

Using “grobs”, i.e. graphic objects from ggplot2 , which can be inserted in the plot region using plot
coordinates;
Using ggdraw from package cowplot , which allows to arrange new plots anywhere on the
graphic device, including outer margins, based on relative position.

Here is a simple example illustrating the difference between the two, and their use. We first prepare a
simple graph showing 11 points, with regular axes and grid ( g1 ):

(g1 <- qplot(0:10, 0:10))

https://www.r-spatial.org/r/2018/10/25/ggplot2-sf-3.html 3/26
23/10/2020 Drawing beautiful maps programmatically with R, sf and ggplot2 — Part 3: Layouts

Graphs from ggplot2 can be saved, like any other R object. That allows to reuse and update the graph
later on. For instance, we store in g1_void , a simplified version of this graph only the point data, but no
decoration:

(g1_void <- g1 + theme_void() + theme(panel.border = element_rect(colour = "black",


fill = NA)))

The function annotation_custom allows to arrange graphs together in the form of grobs (generated
with ggplotGrob ). Here we first plot the full graph g1 , and then add two instances of g1_void in the
upper-left and bottom-right corners of the plot region (as defined by xmin , xmax , ymin , and ymax ):

Using grobs, and annotation_custom :

g1 +
annotation_custom(
grob = ggplotGrob(g1_void),
xmin = 0,
xmax = 3,
ymin = 5,

https://www.r-spatial.org/r/2018/10/25/ggplot2-sf-3.html 4/26
23/10/2020 Drawing beautiful maps programmatically with R, sf and ggplot2 — Part 3: Layouts

ymax = 10
) +
annotation_custom(
grob = ggplotGrob(g1_void),
xmin = 5,
xmax = 10,
ymin = 0,
ymax = 3
)

https://www.r-spatial.org/r/2018/10/25/ggplot2-sf-3.html 5/26
23/10/2020 Drawing beautiful maps programmatically with R, sf and ggplot2 — Part 3: Layouts

An alternative using the function ggdraw from the package cowplot allows to use relative positioning
in the entire plot device. In this case, we build the graph on top of g1 , but the initial call to ggdraw
could actually be left empty to arrange subplots on an empty plot. Width and height of the subplots are
relative from 0 to 1, as well x and y coordinates ([0,0] being the lower-left corner, [1,1] being the upper-
right corner). Note that in this case, subplots are not limited to the actual plot region, but can be added
anywhere on the device:

library(“cowplot”) ggdraw(g1) + draw_plot(g1_void, width = 0.25, height = 0.5, x = 0.02, y = 0.48) +


draw_plot(g1_void, width = 0.5, height = 0.25, x = 0.75, y = 0.09)

https://www.r-spatial.org/r/2018/10/25/ggplot2-sf-3.html 6/26
23/10/2020 Drawing beautiful maps programmatically with R, sf and ggplot2 — Part 3: Layouts

Several maps side by side or on a grid


In this section, we present a way to arrange several maps side by side on a grid. While this could be
achieved manually after exporting each individual map, this allows to 1) have reproducible code to this
end; 2) full control on how individual maps are positioned.

In this example, a zoom in on the Gulf of Mexico is placed on the side of the world map (including its
legend). This illustrates how to use a custom grid, which can be made a lot more complex with more
elements.

We now prepare the subplots, starting by the world map with a rectangle around the Gulf of Mexico (see
Section 1 and 2 for the details of how to prepare this map):

Prepare the subplots, #1 world map:

(gworld <- ggplot(data = world) +


geom_sf(aes(fill = region_wb)) +
geom_rect(xmin = -102.15, xmax = -74.12, ymin = 7.65, ymax = 33.97,
fill = NA, colour = "black", size = 1.5) +
scale_fill_viridis_d(option = "plasma") +
theme(panel.background = element_rect(fill = "azure"),
panel.border = element_rect(fill = NA)))

https://www.r-spatial.org/r/2018/10/25/ggplot2-sf-3.html 7/26
23/10/2020 Drawing beautiful maps programmatically with R, sf and ggplot2 — Part 3: Layouts

The second map is very similar, but centered on the Gulf of Mexico (using coord_sf ):

(ggulf <- ggplot(data = world) +


geom_sf(aes(fill = region_wb)) +
annotate(geom = "text", x = -90, y = 26, label = "Gulf of Mexico",
fontface = "italic", color = "grey22", size = 6) +
coord_sf(xlim = c(-102.15, -74.12), ylim = c(7.65, 33.97), expand = FALSE) +
scale_fill_viridis_d(option = "plasma") +
theme(legend.position = "none", axis.title.x = element_blank(),
axis.title.y = element_blank(), panel.background = element_rect(fill = "azure"),
panel.border = element_rect(fill = NA)))

https://www.r-spatial.org/r/2018/10/25/ggplot2-sf-3.html 8/26
23/10/2020 Drawing beautiful maps programmatically with R, sf and ggplot2 — Part 3: Layouts

Finally, we just need to arrange these two maps, which can be easily done with annotation_custom .
Note that in this case, we use an empty call to ggplot to position the two maps on an empty
background (of size 3.3 × 1):

ggplot() +
coord_equal(xlim = c(0, 3.3), ylim = c(0, 1), expand = FALSE) +
annotation_custom(ggplotGrob(plot1), xmin = 0, xmax = 1.5, ymin = 0,
ymax = 1) +
annotation_custom(ggplotGrob(plot2), xmin = 1.5, xmax = 3, ymin = 0,

https://www.r-spatial.org/r/2018/10/25/ggplot2-sf-3.html 9/26
23/10/2020 Drawing beautiful maps programmatically with R, sf and ggplot2 — Part 3: Layouts

ymax = 1) +
theme_void()

The second approach using the function plot_grid from cowplot to arrange ggplot figures, is
quite versatile. Any ggplot figure can be arranged just like the figure above. Several arguments adjust
map placement, such as nrow and ncol which define the number of row and columns, respectively,
and rel_widths which establishes the relative width of each map. In our case, we want both maps on
a single row, the first map gworld to have a relative width of 2.3 , and the map ggulf a relative
width of 1 .

plot_grid(gworld, ggulf, nrow = 1, rel_widths = c(2.3, 1))

https://www.r-spatial.org/r/2018/10/25/ggplot2-sf-3.html 10/26
23/10/2020 Drawing beautiful maps programmatically with R, sf and ggplot2 — Part 3: Layouts

The argument align can be used to align subplots horizontally ( align = "h" ), vertically ( align =
"v" ), or both ( align = "hv" ), so that the axes and plot region match each other. Note also the
existence of get_legend ( cowplot ), which extract the legend of a plot, which can then be used as
any object (for instance, to place it precisely somewhere on the map).

Both maps created above (using ggplot and annotation_custom , or using cowplot and
plot_grid ) can be saved as usual using ggsave (to be used after plotting the desired map):

ggsave("grid.pdf", width = 15, height = 5)

Map insets
To inset maps directly on a background map, both solutions presented earlier are viable (and one might
prefer one or the other depending on relative or absolute coordinates). We will illustrate this using a map
of the 50 states of the United States, including Alaska and Hawaii (note: both Alaska and Hawaii will not
be to scale).

We start by preparing the continental states first, using the reference US National Atlas Equal Area
projection (CRS 2163). The main trick is to find the right coordinates, in the projection used, and this

https://www.r-spatial.org/r/2018/10/25/ggplot2-sf-3.html 11/26
23/10/2020 Drawing beautiful maps programmatically with R, sf and ggplot2 — Part 3: Layouts

may cause some fine tuning at each step. Here, we enlarge the extent of the plot region on purpose to
give some room for the insets:

usa <- subset(world, admin == "United States of America")


(mainland <- ggplot(data = usa) +
geom_sf(fill = "cornsilk") +
coord_sf(crs = st_crs(2163), xlim = c(-2500000, 2500000), ylim = c(-2300000,
730000)))

The Alaska map is plotted using the reference Alaska Albers projection (CRS 3467). Note that graticules
and coordinates are removed with datum = NA :

https://www.r-spatial.org/r/2018/10/25/ggplot2-sf-3.html 12/26
23/10/2020 Drawing beautiful maps programmatically with R, sf and ggplot2 — Part 3: Layouts

(alaska <- ggplot(data = usa) +


geom_sf(fill = "cornsilk") +
coord_sf(crs = st_crs(3467), xlim = c(-2400000, 1600000), ylim = c(200000,
2500000), expand = FALSE, datum = NA))

And now the map of Hawaii, plotted using the reference Old Hawaiian projection (CRS 4135):

(hawaii <- ggplot(data = usa) +


geom_sf(fill = "cornsilk") +
coord_sf(crs = st_crs(4135), xlim = c(-161, -154), ylim = c(18,
23), expand = FALSE, datum = NA))

https://www.r-spatial.org/r/2018/10/25/ggplot2-sf-3.html 13/26
23/10/2020 Drawing beautiful maps programmatically with R, sf and ggplot2 — Part 3: Layouts

The final map can be created using ggplot2 only, with the help of the function annotation_custom. In this
case, we use arbitrary ratios based on the size of the subsets above (note the difference based on
maximum minus minimum x/y coordinates):

mainland +
annotation_custom(
grob = ggplotGrob(alaska),
xmin = -2750000,
xmax = -2750000 + (1600000 - (-2400000))/2.5,
ymin = -2450000,
ymax = -2450000 + (2500000 - 200000)/2.5
) +
annotation_custom(
grob = ggplotGrob(hawaii),
xmin = -1250000,
xmax = -1250000 + (-154 - (-161))*120000,
https://www.r-spatial.org/r/2018/10/25/ggplot2-sf-3.html 14/26
23/10/2020 Drawing beautiful maps programmatically with R, sf and ggplot2 — Part 3: Layouts

ymin = -2450000,
ymax = -2450000 + (23 - 18)*120000
)

The same can be achieved with the same logic using cowplot and the function draw_plot, in which case
it is easier to define the ratios of Alaska and Hawaii first:

(ratioAlaska <- (2500000 - 200000) / (1600000 - (-2400000)))

## [1] 0.575

(ratioHawaii <- (23 - 18) / (-154 - (-161)))

https://www.r-spatial.org/r/2018/10/25/ggplot2-sf-3.html 15/26
23/10/2020 Drawing beautiful maps programmatically with R, sf and ggplot2 — Part 3: Layouts

## [1] 0.7142857

ggdraw(mainland) +
draw_plot(alaska, width = 0.26, height = 0.26 * 10/6 * ratioAlaska,
x = 0.05, y = 0.05) +
draw_plot(hawaii, width = 0.15, height = 0.15 * 10/6 * ratioHawaii,
x = 0.3, y = 0.05)

Again, both plots can be saved using ggsave:

ggsave("map-us-ggdraw.pdf", width = 10, height = 6)

https://www.r-spatial.org/r/2018/10/25/ggplot2-sf-3.html 16/26
23/10/2020 Drawing beautiful maps programmatically with R, sf and ggplot2 — Part 3: Layouts

Several maps connected with arrows


To bring about a more lively map arrangement, arrows can be used to direct the viewer’s eyes to specific
areas in the plot. The next example will create a map with zoomed in areas, connected by arrows.

We start by creating the general map, here a map of Florida with the site locations (see Tutorial 2 for the
details):

sites <- st_as_sf(data.frame(longitude = c(-80.15, -80.1), latitude = c(26.5,


26.8)), coords = c("longitude", "latitude"), crs = 4326,
agr = "constant")

(florida <- ggplot(data = world) +


geom_sf(fill = "antiquewhite1") +
geom_sf(data = sites, size = 4, shape = 23, fill = "darkred") +
annotate(geom = "text", x = -85.5, y = 27.5, label = "Gulf of Mexico",
color = "grey22", size = 4.5) +
coord_sf(xlim = c(-87.35, -79.5), ylim = c(24.1, 30.8)) +
xlab("Longitude")+ ylab("Latitude")+
theme(panel.grid.major = element_line(colour = gray(0.5), linetype = "dashed",
size = 0.5), panel.background = element_rect(fill = "aliceblue"),
panel.border = element_rect(fill = NA)))

https://www.r-spatial.org/r/2018/10/25/ggplot2-sf-3.html 17/26
23/10/2020 Drawing beautiful maps programmatically with R, sf and ggplot2 — Part 3: Layouts

We then prepare two study sites (simply called A and B here):

(siteA <- ggplot(data = world) +


geom_sf(fill = "antiquewhite1") +
geom_sf(data = sites, size = 4, shape = 23, fill = "darkred") +
coord_sf(xlim = c(-80.25, -79.95), ylim = c(26.65, 26.95), expand = FALSE) +
annotate("text", x = -80.18, y = 26.92, label= "Site A", size = 6) +
theme_void() +
theme(panel.grid.major = element_line(colour = gray(0.5), linetype = "dashed",

https://www.r-spatial.org/r/2018/10/25/ggplot2-sf-3.html 18/26
23/10/2020 Drawing beautiful maps programmatically with R, sf and ggplot2 — Part 3: Layouts

size = 0.5), panel.background = element_rect(fill = "aliceblue"),


panel.border = element_rect(fill = NA)))

(siteB <- ggplot(data = world) +


geom_sf(fill = "antiquewhite1") +
geom_sf(data = sites, size = 4, shape = 23, fill = "darkred") +
coord_sf(xlim = c(-80.3, -80), ylim = c(26.35, 26.65), expand = FALSE) +
annotate("text", x = -80.23, y = 26.62, label= "Site B", size = 6) +
theme_void() +
theme(panel.grid.major = element_line(colour = gray(0.5), linetype = "dashed",
size = 0.5), panel.background = element_rect(fill = "aliceblue"),
panel.border = element_rect(fill = NA)))

https://www.r-spatial.org/r/2018/10/25/ggplot2-sf-3.html 19/26
23/10/2020 Drawing beautiful maps programmatically with R, sf and ggplot2 — Part 3: Layouts

As we want to connect the two subplots to main map using arrows, the coordinates of the two arrows will
need to be specified before plotting. We prepare a data.frame storing start and end coordinates (x1 and
x2 on the x-axis, y1 and y2 on the y-axis):

arrowA <- data.frame(x1 = 18.5, x2 = 23, y1 = 9.5, y2 = 14.5)


arrowB <- data.frame(x1 = 18.5, x2 = 23, y1 = 8.5, y2 = 6.5)

Using ggplot only, we simply follow the same approach as before to place several maps side by side,
and then add arrows using the function geom_segment and the argument arrow = arrow():

ggplot() +
coord_equal(xlim = c(0, 28), ylim = c(0, 20), expand = FALSE) +
annotation_custom(ggplotGrob(florida), xmin = 0, xmax = 20, ymin = 0,
ymax = 20) +
annotation_custom(ggplotGrob(siteA), xmin = 20, xmax = 28, ymin = 11.25,
ymax = 19) +
annotation_custom(ggplotGrob(siteB), xmin = 20, xmax = 28, ymin = 2.5,
ymax = 10.25) +
geom_segment(aes(x = x1, y = y1, xend = x2, yend = y2), data = arrowA,
https://www.r-spatial.org/r/2018/10/25/ggplot2-sf-3.html 20/26
23/10/2020 Drawing beautiful maps programmatically with R, sf and ggplot2 — Part 3: Layouts

arrow = arrow(), lineend = "round") +


geom_segment(aes(x = x1, y = y1, xend = x2, yend = y2), data = arrowB,
arrow = arrow(), lineend = "round") +
theme_void()

The package cowplot (with draw_plot) can also be used for a similar result, with maybe a somewhat
easier syntax:

ggdraw(xlim = c(0, 28), ylim = c(0, 20)) +


draw_plot(florida, x = 0, y = 0, width = 20, height = 20) +
https://www.r-spatial.org/r/2018/10/25/ggplot2-sf-3.html 21/26
23/10/2020 Drawing beautiful maps programmatically with R, sf and ggplot2 — Part 3: Layouts

draw_plot(siteA, x = 20, y = 11.25, width = 8, height = 8) +


draw_plot(siteB, x = 20, y = 2.5, width = 8, height = 8) +
geom_segment(aes(x = x1, y = y1, xend = x2, yend = y2), data = arrowA,
arrow = arrow(), lineend = "round") +
geom_segment(aes(x = x1, y = y1, xend = x2, yend = y2), data = arrowB,
arrow = arrow(), lineend = "round")

Again, both plot can be saved using ggsave:

ggsave("florida-sites.pdf", width = 10, height = 7)

https://www.r-spatial.org/r/2018/10/25/ggplot2-sf-3.html 22/26
23/10/2020 Drawing beautiful maps programmatically with R, sf and ggplot2 — Part 3: Layouts

r-spatial

[email protected] r-spatial R Spatial software blogs and ideas


edzerpebesma

ALSO ON R-SPATIAL

Reproducible Spatial indexes coming Scalable Earth Does R understand


assignments with … to sf Observation … physical quantities?

4 years ago • 6 comments 3 years ago • 1 comment 4 years ago • 2 comments 4 years ago • 3 comments

Introduction Spatial indexes give you fast The analysis of non-trivial [view raw Rmd] Stevens’s
results on spatial amounts of Earth measurement scales S.S.
queries,such as finding … Observation (EO) data is … Stevens’s classical 1946 …

10 Comments r-spatial 🔒 Disqus' Privacy Policy  Rafael Monteiro

 Recommend 2 t Tweet f Share Sort by Best

⚠ r-spatial requires you to verify your email address before posting. Send verification email to ×
[email protected]

https://www.r-spatial.org/r/2018/10/25/ggplot2-sf-3.html 23/26
23/10/2020 Drawing beautiful maps programmatically with R, sf and ggplot2 — Part 3: Layouts

Join the discussion…

Jessica Gorzo • a year ago


In the code block where you combine the maps side by side with annotation custom, should it be "gworld" and
"ggulf" instead of "plot1" and "plot2"?
9△ ▽ • Reply • Share ›

Paul Murrell • 2 years ago


You can make the positioning of those lines between the maps a bit less manual with a little low-level 'grid'
code. See https://gist.github.com/pmu...
1△ ▽ • Reply • Share ›

Mathieu Basille > Paul Murrell • 2 years ago


Thanks Paul for your comment! Sorry to not answer earlier, we were in the process of revising the 3
tutorials (mostly text edits, plus the use of 'rnaturalearth' instead of 'rworldmap'), which should be on-line
soon!

I see the point of using site coordinates to adjust the lines precisely (if that is desirable — I don't think it
is necessarily the case here, as having aligned arrows on the X-axis gives a nice output). Do I
understand correctly though that you still have to figure out precisely what the points are on the device?
Would that work for instance if there were hundreds of points plotted on the map?
△ ▽ • Reply • Share ›

Paul Murrell > Mathieu Basille • 2 years ago


Yes, all that work only makes sense if you actually want the precision :)

However, the code is mostly automated; it works off the locations of the points that you have
added to each map. There is some mental work required to figure out which point is which, but
that can then be enshrined in code. So the idea should scale.

The other manual aspect is details like offsetting the start or end points by a few mm and
dictating angles of incidence. These may scale less well which may mean less fine tuning is
possible at larger scale.

https://www.r-spatial.org/r/2018/10/25/ggplot2-sf-3.html
△ ▽ • Reply • Share › 24/26
23/10/2020 Drawing beautiful maps programmatically with R, sf and ggplot2 — Part 3: Layouts
△ ▽ • Reply • Share ›

Nick Reisner • 4 months ago


I'm a highschooler with an cool internship for which I had to learn GIS mapping in R. This saved me! Thank
you!
△ ▽ • Reply • Share ›

Patrick Wen • a year ago


I noted when projection is changed from default to CRS 2163/3467, xlim changed from around 100 to 2500000.
I would like to know: (1) how did the author determine the value of xlim when CRS is changed? (2) Why
mainland, Alaska, and Hawaii applied different CRS? How were the CRSs determined?
△ ▽ • Reply • Share ›

Brett • a year ago


I'd like to add the United States inland waterway network to my map. Do I need to add the waterway network as
a line? Any insight is appreciated
△ ▽ • Reply • Share ›

Mathieu Basille > Brett • a year ago


The most important part will be to find a good dataset for the waterway network — maybe here, I
couldn't find an easy and open dataset.

Then all you have to do is to convert it to sf, and eventually plot it as a ggplot layer using geom_path.
△ ▽ • Reply • Share ›

Luiz Carlos Junior • a year ago


Hello! How can I put the states of Brazil?
△ ▽ • Reply • Share ›

peter2108 > Luiz Carlos Junior • a year ago


Try https://gadm.org/download_c...
△ ▽ • Reply • Share ›

✉ d
https://www.r-spatial.org/r/2018/10/25/ggplot2-sf-3.html ⚠ 25/26
23/10/2020 Drawing beautiful maps programmatically with R, sf and ggplot2 — Part 3: Layouts

✉S b ib d Add Di t it Add Di Add ⚠ D N t S ll M D t

https://www.r-spatial.org/r/2018/10/25/ggplot2-sf-3.html 26/26

You might also like