Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ricardo-bion/medium_visualization
https://github.com/ricardo-bion/medium_visualization
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/ricardo-bion/medium_visualization
- Owner: ricardo-bion
- Created: 2016-04-07T03:07:58.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-09-10T01:16:38.000Z (about 7 years ago)
- Last Synced: 2024-05-21T02:55:38.656Z (6 months ago)
- Language: R
- Homepage: https://twitter.com/ricardobion
- Size: 13.4 MB
- Stars: 85
- Watchers: 11
- Forks: 26
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
Awesome Lists containing this project
README
---
title: "500k top Airbnb trips: created in R with ggplot2"
output:
html_document:
fig_height: 6
fig_width: 12
keep_md: yes
---A few people asked for a high-resolution image and the code that I used to generate the ggplot2 visualization on my recent Medium post ["Using R Packages and Education to Scale Data Sience at Airbnb"](https://medium.com/airbnb-engineering/using-r-packages-and-education-to-scale-data-science-at-airbnb-906faa58e12d).
### High-res image:
![](https://dl.dropboxusercontent.com/u/2364714/top_airbnb_trips.png)
[**Link to high-res image for download**](https://dl.dropboxusercontent.com/u/2364714/top_airbnb_trips.png)
### R code:
```{r}
library(ggplot2)
library(ggmap)
library(sp)
library(grid)
library(geosphere)
library(plyr)
``````{r}
# source the theme_map for ggplot2
source("https://dl.dropboxusercontent.com/u/2364714/theme_map.R")# in the original post I had a data.frame with 500k rows of top origin destination pairs
trips <- data.frame(origin = c("San Francisco", "Sydney"),
destination = c("Paris", "Tokyo"),
stringsAsFactors = FALSE)
# get lat and lon of cities
trips$geocode_origin <- suppressMessages(geocode(trips$origin))
trips$geocode_destination <- suppressMessages(geocode(trips$destination))# get intermediate points between the two locations
arch <- gcIntermediate(trips$geocode_origin,
trips$geocode_destination,
n=100,
breakAtDateLine=FALSE,
addStartEnd=TRUE, sp=TRUE)# http://docs.ggplot2.org/0.9.3.1/fortify.map.html
arch_fortified <- ldply(arch@lines, fortify)# a few lines of ggplot2 code
ggplot() +
geom_line(aes(long,lat,group=group), data=arch_fortified, alpha=0.1,size=1, colour="skyblue1") +
coord_cartesian(ylim =c(-45, 70), xlim=c(-165, 165)) +
theme_map() +
geom_point(aes(lon, lat),data=trips$geocode_origin, alpha = 0.8, size = 1, colour = "white") +
geom_point(aes(lon, lat),data=trips$geocode_destination, alpha = 0.8, size = 1, colour = "white")```
### Growth over time:
![](https://dl.dropboxusercontent.com/u/2364714/popular_routes.gif)