Pendahuluan
Package Installation
library(ggplot2)
library(tidyverse)
Data & Visualisasi
EUvax <- read.csv("/Users/user/Downloads/EUvaccine.csv")
dataworld <- map_data("world")
dataEU <- left_join(dataworld, EUvax, by="region")
dataEU_vac <- dataEU %>% filter(!is.na(dataEU$Perc_vaccinated))
ggplot(dataEU_vac, aes( x = long, y = lat, group=group)) +
geom_polygon(aes(fill = Perc_vaccinated), color = "black")+
scale_fill_gradient(name = "% vaccinated", low = "yellow", high = "red", na.value = "green")+
theme(axis.text.x = element_blank(),
axis.text.y = element_blank(),
axis.ticks = element_blank(),
axis.title.y=element_blank(),
axis.title.x=element_blank(),
rect = element_blank())
arrests <- USArrests
arrests$region <- tolower(rownames(USArrests))
states_map <- map_data("state")
arrests_map <- left_join(states_map, arrests, by = "region")
ggplot(arrests_map, aes(long, lat, group = group))+
geom_polygon(aes(fill = Assault), color = "white")+
scale_fill_viridis_c(option = "C") +
theme_classic()
library("ggplot2")
library("sf")
## Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE
library("rnaturalearth")
library("rnaturalearthdata")
##
## Attaching package: 'rnaturalearthdata'
## The following object is masked from 'package:rnaturalearth':
##
## countries110
library(sf)
library(ggspatial)
world <- ne_countries(scale = "medium", returnclass = "sf") # part of `naturalearth` package
ggplot(data = world) +
geom_sf()
ggplot(data = world) +
geom_sf(aes(fill = pop_est)) +
scale_fill_viridis_c(option = "volcano")
## Warning in viridisLite::viridis(n, alpha, begin, end, direction, option):
## Option 'volcano' does not exist. Defaulting to 'viridis'.
ggplot(data = world) +
geom_sf() +
coord_sf(xlim = c(-102.15, -74.12), ylim = c(7.65, 33.97), expand = FALSE)
scale_fill_viridis_c(option = "magma")
## <ScaleContinuous>
## Range:
## Limits: 0 -- 1
world_points <- st_centroid(world)
## Warning: st_centroid assumes attributes are constant over geometries
world_points <- cbind(world, st_coordinates(st_centroid(world$geometry)))
ggplot(data = world) +
geom_sf() +
geom_text(data= world_points,aes(x=X, y=Y, label=name),
color = "pink", fontface = "bold", check_overlap = FALSE) +
annotate(geom = "text", x = -90, y = 26, label = "Gulf of Mexico",
fontface = "italic", color = "orange", size = 6) +
annotation_north_arrow(location = "bl", which_north = "true",
pad_x = unit(0.75, "in"), pad_y = unit(0.5, "in"),
style = north_arrow_fancy_orienteering) +
coord_sf(xlim = c(-102.15, -74.12), ylim = c(7.65, 33.97), expand = F) +
theme_bw()
# saving the map
# ggsave("filename")
Opsi untuk visualisasi spasial: 1. Looker 2. Python 3. Tableau 4. PowerBI 5. Quicksight 6. SUperset 7. etc.