library(tidyverse)
Overview
This a map of Japan
with cities from mapdata::get('world.cities')
.
source: https://cran.r-project.org/web/packages/ggfortify/vignettes/plot_map.html
library(mapdata)
# Check all available geospatial objects:
# help(package='mapdata')
<- ggplot2::map_data("japan")
japan# Map of Japan:
map('japan',col="black", lwd=1, mar=rep(0,4) )
<- map_data("japan") %>%
japan select(lon = long, lat, group, id = region)
head(japan)
<- get('world.cities')
cities <- cities[cities$country.etc == 'Japan', ]
cities head(cities)
<- cities%>%
jp_popcount(name,pop,lat,long)%>%
arrange(-pop)%>%
slice(1:10)
<- japan%>%
full full_join(jp_pop,by=c("lon"="long","lat"))
library(extrafont)
library(showtext)
library(cowplot)
library(ggstream)
library(colorspace)
## Automatically use showtext to render text for future devices
showtext_auto()
## Tell showtext the resolution of the device,
## only needed for bitmap graphics. Default is 96
showtext_opts(dpi = 320)
## Loading Google fonts (https://fonts.google.com/)
font_add_google("Covered By Your Grace", "grace")
library(RColorBrewer)
<- 47
n = brewer.pal.info[brewer.pal.info$category == 'qual',]
qual_col_pals = unlist(mapply(brewer.pal, qual_col_pals$maxcolors, rownames(qual_col_pals)))
col_vector
library(RColorBrewer)
<- ggplot() +
finalgeom_point(data = cities,
mapping = aes(x = long, y = lat),
colour = 'blue', size = 0.1) +
geom_polygon(data=japan,
mapping = aes(x = lon,y = lat,group = group,fill=id)) +
geom_point(data=full,
mapping = aes(x = lon,y = lat, group = group,
size=pop),alpha=0.4,color="black") +
geom_text(aes(x = 132, y = 40),label = "Japan",size=20,family="grace") +
geom_text(aes(x = 142, y = 45),label = "Hokkaido",size=12,family="grace") +
geom_text(aes(x = 142, y = 37),label = "Honshu",size=12,family="grace") +
geom_text(aes(x = 132, y = 30),label = "Kyushu",size=12,family="grace") +
geom_text(aes(x = 138, y = 33),label = "Shikoku",size=12,family="grace") +
geom_text(aes(x = 130, y = 25),label = "Okinawa Island",size=12,family="grace") +
::geom_text_repel(data = jp_pop,
ggrepelmapping = aes(x = long, y = lat,label=name),family="grace") +
scale_fill_manual(values=col_vector)+
scale_size_area(label = scales::comma,max_size=6)+
guides(fill=guide_legend(ncol=2,keywidth = unit(0.1, 'cm')),
size=guide_legend(ncol=4)) +
labs(title="Japanese Archipelago",
subtitle="Japan is the largest island country in East Asia and the fourth largest island country in the world - Wiki",
size="Population",fill="Regions",
caption = "Datasource: {ggplot2}::map_data - #30DayMapChallenge - Infographics: Federica Gazzelloni")+
coord_map() +
::theme_map()+
ggthemestheme(text = element_text(family="grace",size=12),
legend.position = c(-0.3,0.1),
legend.background = element_blank(),
legend.key.size = unit(0.1, 'cm'),
plot.title = element_text(size=25,vjust=-2),
plot.subtitle = element_text(vjust=-5),
plot.caption = element_text(size=14)
)
final
# save final plot
::agg_png(here::here("R_general_resources/30DayMapChallenge/day19_islands/islands.png"),
raggres = 320, width = 12, height = 8, units = "in")
finaldev.off()