Skip to content

Commit

Permalink
Teak figures for #8
Browse files Browse the repository at this point in the history
  • Loading branch information
Robinlovelace committed Mar 27, 2020
1 parent 5495689 commit 274f670
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ See [whythegap.london](http://whythegap.london) for the campaign for "Cycle Hire
"There are lots of anomalies in that cycle hire scheme. We are going to explore them."
]

```{r facet-map, out.width="50%", fig.cap="Changes in the spatial and social distribution of docking stations over time, 2010-2019, showing four stages of expansion. Zone colour represents income decile, with 1 (white) representing the lowest income areas and 10 represents (blue) wealthy areas (top). The percentage of docking station in each income decile over time (blue) overlaying a representative distribution of income deciles for London (grey) for the same years (bottom). Note: a distribution representative of national income levels would be flat.", fig.show='hold', fig.align='left', eval=TRUE}
```{r facet-map, out.width="100%", fig.cap="Changes in the spatial and social distribution of docking stations over time, 2010-2019, showing four stages of expansion. Zone colour represents income decile, with 1 (white) representing the lowest income areas and 10 represents (blue) wealthy areas (top). The percentage of docking station in each income decile over time (blue) overlaying a representative distribution of income deciles for London (grey) for the same years (bottom). Note: a distribution representative of national income levels would be flat.", fig.show='hold', fig.align='left', eval=TRUE}
# note: previous caption said: Point size is proportional to capacity of docking stations, ranging from 10 to 70
# file.edit("stations-classification.Rmd") # see stations-classification.Rmd for source code
knitr::include_graphics(c("figures/facet-imd.png", # make single line
Expand Down
11 changes: 6 additions & 5 deletions code/stations-imd-facet.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ tm_shape(lsoa_lnd_joined) + tm_fill("Income decile", palette = "viridis") +
m4 = tm_shape(lsoa_lnd_joined, bbox = st_bbox(bikelocations_sf4)) +
tm_fill("Income decile", palette = "Blues", alpha = 0.8, legend.is.portrait = FALSE) +
tm_shape(bikelocations_sf4) +
tm_dots(size = 0.1, title.size = "Bikes") +
tm_facets(by = "year", free.coords = FALSE) +
tm_dots(size = 0.05, title.size = "Bikes") +
tm_facets(by = "year", free.coords = FALSE, nrow = 1) +
# tm_layout(scale = 1, legend.show = F) # works
# tm_layout(scale = 1, legend.outside.position = c("right"), legend.stack = "horizontal")
tm_layout(scale = 1, legend.outside.position = "bottom", legend.outside.size = 0.15)
tm_layout(scale = 0.5, legend.outside.position = "bottom", legend.outside.size = 0.2)
m4
tmap_save(m4, "figures/facet-imd.png", width = 6, height = 5)
magick::image_read("figures/facet-imd.png")
tmap_save(m4, "figures/facet-imd.png", width = 6, height = 2)
# magick::image_read("figures/facet-imd.png")
browseURL("figures/facet-imd.png")
Binary file modified figures/facet-imd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figures/map-am-pm-peaks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figures/stations-imd-facet-4-grey.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 29 additions & 5 deletions stations-classification.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,25 @@ tmap_mode("view")
knitr::opts_chunk$set(eval = TRUE)
```

```{r, eval=FALSE}
install.packages("showtext")
library(showtext)
font_add(family = "Avenir Book", regular = "~/hd/backups/Avenir Book/Avenir Book.ttf")
font_add_google("Gochi Hand", "gochi")
font_add_google("Schoolbell", "bell")
showtext_auto()
x11()
hist(rnorm(1000), breaks = 30, col = "steelblue", border = "white",
main = "", xlab = "", ylab = "")
title("Histogram of Normal Random Numbers", family = "bell", cex.main = 2)
title(ylab = "Frequency", family = "gochi", cex.lab = 2)
text(2, 70, "N = 1000", family = "bell", cex = 2.5)
```



# Input data

Expand Down Expand Up @@ -45,7 +64,7 @@ stations_yearly_lsoa %>%
ggplot(aes(`Income decile`)) +
geom_bar(fill = "blue") +
facet_wrap(~year) +
ggthemes::theme_clean()
ggthemes::theme_clean(base_family = "gochi")
# props
# source("get-imd-data.R")
Expand Down Expand Up @@ -109,9 +128,14 @@ stations_yearly_4 %>% ggplot() +
scale_y_continuous(labels = scales::percent_format()) +
scale_x_continuous(breaks = 1:10) +
facet_wrap(~year, nrow = 1) +
ylab("Proportion of docking stations in each income decile")
ggsave("figures/stations-imd-facet-4-grey.png", width = 6, height = 5.5)
ylab("% stations in each income decile") +
theme_minimal()
# theme_set(ggthemes::theme_clean(base_family = "Avenir Book"))
# theme(axis.title=element_blank(), panel.border = element_blank(),
# strip.text.y = element_text(angle=0))
ggsave("figures/stations-imd-facet-4-grey.png", width = 6, height = 3)
magick::image_read("figures/stations-imd-facet-4-grey.png")
# calculate scores
Expand Down Expand Up @@ -213,7 +237,7 @@ piggyback::pb_upload("stations_clean_am_pm.geojson")
tmap_mode("plot")
m = tm_shape(stations %>% select(operator_name, trips_per_year, trips_per_year_am, trips_per_year_pm, years_in_operation)) +
tm_dots(size = c("trips_per_year_am", "trips_per_year_pm"),
col = "years_in_operation", palette = "viridis", contrast = c(0, 0.8), alpha = 0.5, scale = 1.5, title.size = "") +
col = "years_in_operation", palette = "Spectral", contrast = c(0, 0.8), alpha = 0.5, scale = 1.5, title.size = "") +
tm_layout(panel.show = TRUE,
panel.labels = c("AM (06:00 - 10:00)", "PM (16:00 - 20:00)"),
legend.outside = T, title = "N. trips/year") +
Expand Down

0 comments on commit 274f670

Please sign in to comment.