Create the following figure, using the data included in the R Markdown file.
# PACKAGES
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.4.4 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(maps)
##
## Attaching package: 'maps'
##
## The following object is masked from 'package:purrr':
##
## map
library(ggplot2)
library(ggrepel)
library(mapproj)
library(sf)
## Linking to GEOS 3.11.2, GDAL 3.7.2, PROJ 9.3.0; sf_use_s2() is TRUE
library(cartography)
## This project is in maintenance mode.
## Core functionalities of `cartography` can be found in `mapsf`.
## https://riatelab.github.io/mapsf/
library(mapsf)
library(rnaturalearth)
library(rnaturalearthdata)
##
## Attaching package: 'rnaturalearthdata'
##
## The following object is masked from 'package:rnaturalearth':
##
## countries110
sessionInfo()
## R version 4.3.2 (2023-10-31 ucrt)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 11 x64 (build 22631)
##
## Matrix products: default
##
##
## locale:
## [1] LC_COLLATE=English_United Kingdom.utf8
## [2] LC_CTYPE=English_United Kingdom.utf8
## [3] LC_MONETARY=English_United Kingdom.utf8
## [4] LC_NUMERIC=C
## [5] LC_TIME=English_United Kingdom.utf8
##
## time zone: Europe/London
## tzcode source: internal
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] rnaturalearthdata_1.0.0 rnaturalearth_1.0.1 mapsf_0.9.0
## [4] cartography_3.1.4 sf_1.0-15 mapproj_1.2.11
## [7] ggrepel_0.9.5 maps_3.4.2 lubridate_1.9.3
## [10] forcats_1.0.0 stringr_1.5.1 dplyr_1.1.4
## [13] purrr_1.0.2 readr_2.1.5 tidyr_1.3.1
## [16] tibble_3.2.1 ggplot2_3.4.4 tidyverse_2.0.0
##
## loaded via a namespace (and not attached):
## [1] s2_1.1.6 sass_0.4.8 utf8_1.2.4 generics_0.1.3
## [5] class_7.3-22 KernSmooth_2.23-22 stringi_1.8.3 hms_1.1.3
## [9] digest_0.6.34 magrittr_2.0.3 evaluate_0.23 grid_4.3.2
## [13] timechange_0.3.0 fastmap_1.1.1 jsonlite_1.8.8 e1071_1.7-14
## [17] DBI_1.2.1 httr_1.4.7 fansi_1.0.6 scales_1.3.0
## [21] codetools_0.2-19 jquerylib_0.1.4 cli_3.6.2 rlang_1.1.3
## [25] units_0.8-5 munsell_0.5.0 withr_3.0.0 cachem_1.0.8
## [29] yaml_2.3.8 tools_4.3.2 tzdb_0.4.0 colorspace_2.1-0
## [33] vctrs_0.6.5 R6_2.5.1 proxy_0.4-27 lifecycle_1.0.4
## [37] classInt_0.4-10 pkgconfig_2.0.3 terra_1.7-71 pillar_1.9.0
## [41] bslib_0.6.1 gtable_0.3.4 glue_1.7.0 Rcpp_1.0.12
## [45] xfun_0.41 tidyselect_1.2.0 rstudioapi_0.15.0 knitr_1.45
## [49] maplegend_0.1.0 htmltools_0.5.7 rmarkdown_2.25 wk_0.9.1
## [53] compiler_4.3.2
plot <- my_world_map %>%
left_join(some_data_values) %>%
select(long,
lat,
region,
group,
Score)
ggplot(data = plot,
aes(x = long,
y = lat)) +
geom_polygon(aes(group = group,
fill = Score)) +
scale_fill_distiller(palette= "Greens") +
coord_quickmap()
Create the following figure, using the data included in the R Markdown file.
world <- map_data("world")
CentralAmerica1 <- filter(world,region=="Costa Rica"|
region=="Nicaragua"|
region=="Panama")
my_cities <-maps::world.cities
CA_big_cities <- filter(my_cities,country.etc=="Costa Rica"|
country.etc=="Nicaragua"|
country.etc=="Panama",pop>40000)
add_column(CA_big_cities,Measurement)
## name country.etc pop lat long capital Measurement
## 1 Alajuela Costa Rica 48366 10.02 -84.23 0 50.25882
## 2 Arraijan Panama 81118 8.95 -79.65 0 51.83112
## 3 Bluefields Nicaragua 45703 12.01 -83.77 0 49.66038
## 4 Chinandega Nicaragua 129730 12.63 -87.13 0 50.89720
## 5 Chitre Panama 44735 7.97 -80.42 0 50.48802
## 6 Ciudad Sandino Nicaragua 72109 12.16 -86.34 0 48.74461
## 7 Colon Panama 77983 9.36 -79.90 0 50.02279
## 8 David Panama 84013 8.44 -82.43 0 51.09077
## 9 El Viejo Nicaragua 55268 12.67 -87.18 0 49.86788
## 10 Esteli Nicaragua 99479 13.09 -86.36 0 48.92500
## 11 Granada Nicaragua 90868 11.94 -85.96 0 50.85501
## 12 Jinotega Nicaragua 53055 13.10 -86.00 0 49.63502
## 13 Juigalpa Nicaragua 56712 12.11 -85.38 0 50.16555
## 14 La Chorrera Panama 62359 8.88 -79.78 0 48.75722
## 15 Las Cumbres Panama 73219 9.08 -79.53 0 51.45929
## 16 Leon Nicaragua 146685 12.43 -86.89 0 49.99639
## 17 Liberia Costa Rica 47906 10.64 -85.45 0 49.97912
## 18 Limon Costa Rica 64285 9.99 -83.04 0 50.03211
## 19 Managua Nicaragua 990417 12.15 -86.27 1 48.83272
## 20 Masaya Nicaragua 134516 11.98 -86.10 0 49.48043
## 21 Matagalpa Nicaragua 114628 12.93 -85.93 0 51.37389
## 22 Nueva Guinea Nicaragua 55339 11.69 -84.46 0 51.41233
## 23 Pacora Panama 56414 9.08 -79.28 0 49.59783
## 24 Panama Panama 406070 8.97 -79.53 1 49.56086
## 25 Paraiso Costa Rica 41936 9.83 -83.87 0 51.01061
## 26 San Francisco Costa Rica 59484 9.99 -84.13 0 50.43082
## 27 San Jose Costa Rica 339588 9.93 -84.08 1 50.73393
## 28 San Miguelito Panama 326951 9.03 -79.50 0 49.31933
## 29 Santiago Panama 46284 8.10 -80.97 0 50.32620
## 30 Tipitapa Nicaragua 132672 12.20 -86.10 0 50.90703
## 31 Tocumen Panama 89951 9.08 -79.38 0 49.53732
## 32 Vista Alegre Panama 42451 8.93 -79.70 0 50.00470
ggplot(data = CentralAmerica1,
mapping = aes(x= long,
y= lat,
group =group))+
geom_polygon(color="black",
fill="white") +
geom_point(data = CA_big_cities,
aes(x=long,
y=lat,
group=NULL,
color=Measurement),
size=5,
alpha=.8) +
scale_size_continuous() +
scale_color_distiller(palette= "Oranges") +
theme_classic() +
theme(axis.text.x = element_blank(),axis.text.y=element_blank(),
axis.line = element_blank(),axis.ticks = element_blank())+
labs(x="",y="", title="Panama, Nicaragua, & Costa Rica major cities",
caption ="Population > 40,000")
Create the following figure, using the data included in the R Markdown file.
Note that the code in the .rmd file will import a set of simple features data for South America. Make sure you install any necessary packages.
ggplot()+
geom_sf(data= s_america,
aes(fill=pop_est))+
scale_fill_distiller(palette = 10)