This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The objective is to make a faceted ggplot 'heatmap' with geom_tile where the | |
# rendered tiles in the output PNG file have a fixed width and height, | |
# regardless of whatever else is in the chart. | |
# When ggplot charts are built, the height and width of all components are | |
# predetermined *except* for the facet panels. Thus the approach here is to | |
# render an initial version of the chart to determine the height and width | |
# of the predetermined elements. Then the overall height and width of the | |
# output PNG are calculated based on what is needed to give the rendered | |
# tiles the desired size. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Setup | |
library(conflicted) | |
library(tidyverse) | |
library(lubridate) | |
library(readxl) | |
conflict_prefer("filter", "dplyr") | |
conflict_prefer("lag", "dplyr") | |
conflict_prefer("lead", "dplyr") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
example_dat <- tribble( | |
~year, ~group, ~revenues, ~costs, | |
2015, "Apple", 1000, 500, | |
2016, "Apple", 1500, 600, | |
2017, "Apple", 1200, 550, | |
2015, "Pear", 2000, 1100, | |
2016, "Pear", 2500, 1300, | |
2017, "Pear", 2900, 1500, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Make a Japanese-style timetable using AT public transport data (better version) | |
# You'll need to download AT's GTFS data file first from https://at.govt.nz/about-us/at-data-sources/google-transit-feed/ | |
library(magrittr) | |
library(tidyverse) | |
library(hms) | |
library(lubridate) | |
library(stringr) | |
library(ggthemes) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Make a Japanese-style timetable using AT public transport data | |
# You'll need to download AT's GTFS data file first from https://at.govt.nz/about-us/at-data-sources/google-transit-feed/ | |
library(magrittr) | |
library(tidyverse) | |
library(hms) | |
library(lubridate) | |
library(stringr) | |
library(ggthemes) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ----------------------------------------------------------------------------- | |
# Setup | |
rm(list = ls()) | |
library(magrittr) | |
library(jsonlite) | |
library(httr) | |
library(lubridate) | |
library(tidyverse) | |
library(scales) | |
source("clean-ggplot-theme.R") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Map Christchurch property data | |
# ----------------------------------------------------------------------------- | |
# Setup | |
rm(list = ls()) | |
library(magrittr) | |
library(lubridate) | |
library(tidyverse) | |
library(scales) | |
library(sf) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
dat <- data.frame(x = 1:10, y = runif(10)) | |
chart <- ggplot(dat) + | |
geom_bar(aes(x = x, y = y), stat = "identity") + | |
geom_text(aes(x = 2, y = 1.5, label = "This text is jaggy"), size = 6) | |
print(chart) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ----------------------------------------------------------------------------- | |
# Setup | |
library(magrittr) | |
library(lubridate) | |
library(tidyverse) | |
library(ggplot2) | |
library(scales) | |
source("clean-ggplot-theme.R") | |
# ----------------------------------------------------------------------------- |
NewerOlder