Created
January 28, 2018 03:52
-
-
Save johnjosephhorton/571e81fa81e20ed72d770a62cb4d2dcb to your computer and use it in GitHub Desktop.
This file contains hidden or 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(geofacet) # my forked version | |
library(ggplot2) | |
library(jsonlite) | |
library(ggrepel) | |
# grab top cities | |
cities <- fromJSON("https://gist.githubusercontent.com/Miserlou/c5cd8364bf9b2420bb29/raw/2bf258763cdddd704f8ffd3ea9a3e81d25e2c6f6/cities.json") | |
n <- 50 | |
x <- cities$longitude[1:n] | |
y <- cities$latitude[1:n] | |
index <- as.integer(cities$rank[1:n]) | |
city <- cities$city[1:n] | |
# illustrate putting on n x n grid | |
row <- rank(y) | |
col <- rank(x) | |
df <- data.frame(x,y,row,col,index, city) | |
# raw coordinates | |
ggplot(data = df, aes(x = x,y = y)) + | |
geom_text_repel(aes(label = city)) + | |
theme_bw() | |
# on n x n grid | |
ggplot(data = df, aes(x = col,y = row)) + | |
geom_tile(fill="grey", colour = "black") + | |
geom_text_repel(aes(label = city)) + | |
theme_bw() | |
# grid a reduced grid | |
df <- create_new_grid(x,y,city, num.iterations = 500) | |
# plus results | |
ggplot(data = df, aes(x = new.col,y = new.row)) + | |
geom_point() + | |
geom_tile(fill="grey", colour = "black") + | |
geom_text_repel(aes(label = unit.name), size = 2) + | |
theme_bw() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment