This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.
library(tidyverse)
library(ggspatial)
library(ggrepel)
hungerford_shootings <- read_csv(
"https://mpjashby.github.io/crimemappingdata/hungerford_shootings.csv",
show_col_types = FALSE
)
hungerford_lines <- hungerford_shootings |>
rename(x_end = easting, y_end = northing) |>
mutate(
x_start = lag(x_end),
y_start = lag(y_end)
) |>
drop_na(x_start, y_start)
hungerford_map_town <- ggplot() +
annotation_map_tile(type = "cartolight", zoomin = 0) +
geom_curve(
aes(x = x_start, y = y_start, xend = x_end, yend = y_end),
data = slice(hungerford_lines, 3:n()),
arrow = arrow(length = unit(3, "mm"), type = "closed"),
curvature = -0.2,
colour = "blue4",
linewidth = 1.5
) +
geom_point(
aes(x = easting, y = northing),
data = slice(hungerford_shootings, 3:n()),
shape = 21,
colour = "black",
fill = "cyan",
size = 4
) +
geom_label_repel(
aes(x = easting, y = northing, label = order),
data = slice(hungerford_shootings, 3:n()),
colour = "white",
fill = "blue4",
fontface = "bold",
label.size = NA
) +
annotation_scale(style = "ticks", line_col = "grey40") +
scale_x_continuous(expand = expansion(0.3)) +
scale_y_continuous(expand = expansion(0.3)) +
coord_sf(crs = "EPSG:27700") +
labs(title = "Shootings in Hungerford town (Modified Style)") +
theme_void() +
theme(
panel.border = element_rect(colour = "grey20", fill = NA),
plot.margin = margin(t = 12)
)
hungerford_map_town