library(arc2r) 
library(sf)
library(raster)
library(ggplot2)

data("gemeindegrenzen_zh")
data("swissAlti3D")
plot(gemeindegrenzen_zh)
## 
## plot(st_geometry(gemeindegrenzen_zh))  # 1
## plot(gemeindegrenzen_zh["BEZIRKSNAME"]) # 2
## plot(gemeindegrenzen_zh, max.plot = 1) # 3
## 
## options(sf_max.plot = 1)        # 4
## plot(gemeindegrenzen_zh)
plot(swissAlti3D)
ggplot(gemeindegrenzen_zh) +
  geom_sf()
ggplot(gemeindegrenzen_zh) + 
  geom_sf(aes(fill = BEZIRKSNAME))
ggplot(gemeindegrenzen_zh) + 
  geom_sf(aes(fill = BEZIRKSNAME)) +
  coord_sf(datum = 2056)
ggplot(gemeindegrenzen_zh) + 
  geom_sf(aes(fill = BEZIRKSNAME), colour = "white") +
  labs(title = "Gemeinden des Kantons Zürich nach Bezirk",fill = "") +
  theme_void() +
  theme(legend.position = "bottom")
## swissAlti3D_df <- as.data.frame(swissAlti3D,xy = TRUE) # xy = TRUE adds the x and y coordinates to our dataframe as columns
## 
## ggplot(swissAlti3D_df, aes(x, y, fill = SWISSALTI3D_10_TIFF_CHLV95_LN02_2600_1196)) +
##   geom_raster()
## 
## 
## ggplot(swissAlti3D_df, aes(x, y, fill = SWISSALTI3D_10_TIFF_CHLV95_LN02_2600_1196)) +
##   geom_raster() +
##   scale_fill_viridis_c() +
##   theme_void() +
##   coord_equal() +
##   theme(legend.position = "bottom")
## 
library(tmap)
tmap_mode("plot") # <- to create static plots


tm_shape(gemeindegrenzen_zh) + 
  tm_polygons(col = "BEZIRKSNAME")+
  tm_layout(legend.position = c("right","top"))
tm_shape(gemeindegrenzen_zh) + 
  tm_polygons(col = "BEZIRKSNAME")+
  tm_layout(legend.position = c("right","bottom")) +
  tm_compass()
tm_shape(swissAlti3D) +
  tm_raster()


arc2r/book documentation built on March 5, 2021, 2:10 p.m.