Skip to content

Instantly share code, notes, and snippets.

@grigory93
Last active July 5, 2017 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grigory93/4c0d970a1ca47f22f251796edce5e635 to your computer and use it in GitHub Desktop.
Save grigory93/4c0d970a1ca47f22f251796edce5e635 to your computer and use it in GitHub Desktop.
Small Data Visualization - Vacation Recap
library(googlesheets)
library(dplyr)
library(lubridate)
gsh = gs_title("Rome-Siracusa-vacations")
vdata = gsh %>% gs_read()
vdata$ts = mdy(vdata$Date)
library(ggplot2)
library(ggthemes)
date_breaks = vdata$ts[is.na(ifelse(day(vdata$ts)%%2==1, NA, 1:length(vdata$ts)))]
date_labels = format(date_breaks, "%b-%d")
text_just = ifelse(vdata$Place == 'Rome', 0.25, 0.75)
ggplot(vdata) +
geom_line(aes(ts, Distance, group=1, color=Place), size=1) +
geom_point(aes(ts, Distance, color=Place), size=4) +
scale_x_date(breaks = date_breaks, labels = date_labels) +
geom_text(aes(ts, Distance, label=Label, hjust=text_just), nudge_y = -0.3, family='serif') +
scale_color_manual(values=c('darkred','olivedrab4'), name='Base Cities') +
theme_tufte(ticks = FALSE, base_size = 16, base_family = 'sans') +
theme(axis.text.x = element_text(angle = 0),
legend.position = "bottom") +
labs(title="Italian Vacation - June 19-30, 2017",
subtitle="Miles walked and major attractions each day",
x=NULL, y="Miles")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment