library(sf)
library(osmdata)
library(leaflet)
Overview
This map of Berlin water
is made with data from {osmdata}
package.
source: https://parametricsforarchitecture.wordpress.com/2020/07/21/urban-design-masterplanning-desktop-analysis-automation-through-rstudio-and-shiny/
available_tags("water")
<- "Berlin"
location
<- getbb(location)%>%
berlin_osm opq()%>%
add_osm_feature("water")%>%
osmdata_sf()
<- berlin_osm$osm_points
berlin_water
%>%head berlin_water
<- data.frame(berlin_water$osm_id,
berlin_geo $geometry)
berlin_water
names(berlin_geo)[1]<- "osm_id"
<- merge.data.frame(berlin_water, berlin_geo)
berlin_data
<- data.frame(st_coordinates(berlin_data$geometry))
coord $X <- coord$X
berlin_data$Y <- coord$Y berlin_data
library(magick)
<- magick::image_read("~/Documents/R/R_general_resources/30DayMapChallenge/day5_osm/logo.png") img
<- leaflet() %>%
map addTiles() %>%
setView(lat=52.517317, lng=13.412364, zoom = 14) %>%
addProviderTiles(providers$Stamen.Toner) %>%
addProviderTiles(providers$Stamen.TonerLines,
options = providerTileOptions(opacity = 0.35)) %>%
addProviderTiles(providers$Stamen.TonerLabels)%>%
addCircleMarkers(data = berlin_data,
lat = ~Y,
lng = ~X,
radius = 2.5,
popup = ~water,
color = "midnightblue") %>%
addCircleMarkers(data = berlin_data,
lat = ~Y,
lng = ~X,
radius = 0.05,
popup = ~water,
color = "cyan")
save the plot as .png
library(extrafont)
library(showtext)
font_add_google("Schoolbell", "bell")
showtext_opts(dpi = 320)
showtext_auto(enable = T)
<- ggplot()+
plot geom_blank()+
xlim(0,1932) + ylim(0,1326)+
theme_void()+
theme(plot.background = element_rect(color = "grey14",fill=NA, size=3))
library(cowplot)
library(magick)
<- magick::image_read("~/Documents/R/R_general_resources/30DayMapChallenge/day5_osm/map.png")
image_map
<- cowplot::ggdraw(plot)+
final draw_image(image_map,x = 0.02, y = 0,width =0.95)+
draw_label(label="Datasource: {osmdata} #30DayMapChallenge Day5 - map: Federica Gazzelloni",x=0.5,y=0.03,
fontfamily = "bell") +
draw_label(label="BERLIN WATER",x=0.45,y=0.92,size=50,fontfamily = "bell",fontface="bold")
# save final plot
::agg_png("~/Documents/R/R_general_resources/30DayMapChallenge/day5_osm/osmdata.png",
raggres = 320, width = 11, height = 8, units = "in")
finaldev.off()