Skip to content

Instantly share code, notes, and snippets.

View rcatlord's full-sized avatar

rcatlord

View GitHub Profile
@rcatlord
rcatlord / bloomsday_app
Created July 27, 2016 10:50
Shiny app integrating timevis and leaflet with a literary theme
## Bloomsday app ##
library(shiny) ; library(leaflet) ; library(timevis)
data <- data.frame(
id = sample(seq(20, 50, by=1), 18, replace=FALSE),
content = c("Telemachus",
"Nestor",
"Proteus",
"Calypso",
@rcatlord
rcatlord / data_police_uk_api_in_R
Created June 27, 2017 13:37
Using the data.police.uk API
library(jsonlite)
# df <- jsonlite::fromJSON(txt="https://data.police.uk/api/crimes-street/all-crime?lat=53.444853&lng=-2.278289&date=2017-02")
df <- jsonlite::fromJSON(txt="https://data.police.uk/api/crimes-street/all-crime?poly=52.268,0.543:52.794,0.238:52.130,0.478&date=2017-02")
df$location$longitude <- as.numeric(as.character(df$location$longitude))
df$location$latitude <- as.numeric(as.character(df$location$latitude))
library(tidyverse)
df %>%
count(category) %>%
ggplot(aes(x = reorder(category, n),
library(tidyverse)
plot <- starwars %>%
mutate(name, bmi = mass / ((height / 100) ^ 2)) %>%
ggplot(aes(x = bmi)) +
geom_histogram(fill = "#fc6721", alpha = 0.8, binwidth = 10) +
scale_x_continuous(expand = c(0, 0), limits=c(0, 450)) +
labs(x = "Body Mass Index [kg/m^2]", y = NULL,
title = "BMI distribution for Star Wars characters")
plot
plot +
# remove the background
theme(panel.background = element_blank())
plot +
theme(panel.background = element_blank(),
# hide all the axis tick marks
axis.ticks = element_blank())
plot +
theme(panel.background = element_blank(),
axis.ticks = element_blank(),
# hide the minor grid lines
panel.grid.minor = element_blank(),
# hide vertical major grid lines
panel.grid.major.x = element_blank(),
# change colour and thickness of horizontal grid lines
panel.grid.major.y = element_line(colour = "#757575", size = 0.3))
plot +
theme(panel.background = element_blank(),
axis.ticks = element_blank(),
panel.grid.minor = element_blank(),
panel.grid.major.x = element_blank(),
panel.grid.major.y = element_line(colour = "#757575", size = 0.3),
# change the title colour, font and alignment
plot.title = element_text(colour = "#2c7fb8", size = 14, face = "bold", h = 0),
# change the colour and font of the axis labels
axis.title = element_text(colour = "#212121", size = 10))
theme_demo <- function () {
theme_grey() %+replace%
theme(panel.background = element_blank(),
axis.ticks = element_blank(),
panel.grid.minor = element_blank(),
panel.grid.major.x = element_blank(),
panel.grid.major.y = element_line(colour = "#757575", size = 0.3),
plot.title = element_text(colour = "#2c7fb8", size = 14, face = "bold", h = 0),
axis.title = element_text(colour = "#212121", size = 10))
}
source("https://trafforddatalab.github.io/assets/theme/ggplot2/theme_lab.R")
starwars %>%
mutate(name, bmi = mass / ((height / 100) ^ 2)) %>%
ggplot(aes(x = bmi)) +
geom_histogram(fill = "#fc6721", alpha = 0.8, binwidth = 10) +
scale_x_continuous(expand = c(0, 0), limits=c(0, 450)) +
labs(x = "Body Mass Index [kg/m^2]", y = NULL,
title = "BMI distribution for Star Wars characters") +
theme_lab()
@rcatlord
rcatlord / .block
Last active December 30, 2017 16:21
Typography
license: cc-by-4.0
height: 500
scrolling: no
border: yes