-
-
Save WillForan/45ecccb215c33db0c9c6326d5b64b873 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
#!/usr/bin/env R | |
library(curl) | |
library(dplyr) | |
library(tidyr) | |
library(ggplot2) | |
library(cowplot) | |
library(gridExtra) | |
# get data | |
url <- 'https://docs.google.com/spreadsheets/d/e/2PACX-1vR0TLhKqeEWZsJqbIuZ38bLc3vVeUpPx9rYnS1QG9kp4Wgv9rvCRHplf1fDy4rFbmC1CAQoVLVW3NX7/pub?output=tsv' | |
req <- curl_fetch_memory(url) | |
# into a data frame | |
d <- | |
read.table(text=rawToChar(req$content),sep="\t",quote="",header=T) %>% | |
mutate_each(funs(distmi),matches('Hiking.Distance')) %>% | |
mutate(id=1:n()) | |
# subset places and move from wide to long format | |
places <- | |
d %>% | |
select(matches('Where'),id) %>% | |
gather(place,rank,matches('Where')) %>% | |
mutate(place=gsub('Where..([A-Za-z]+).*','\\1',place)) %>% | |
mutate(rank=factor(as.character(rank),rev(c('Yes!','Okay','If everyone else is','Nope!')))) | |
# start plotting | |
p.d <- ggplot(places) + aes(fill=place,x=as.numeric(rank)) + geom_density(alpha=.9) | |
p.b <- ggplot(places) + aes(fill=place,x=place,y=as.numeric(rank)) + geom_boxplot() +geom_jitter(height=0,color='white',shape=21,width=.1) | |
p.byid <- | |
ggplot(places)+ | |
aes(y=place,x=id,fill=rank) + | |
geom_tile() + | |
theme(axis.text.x=element_blank(), | |
axis.ticks.x=element_blank(), | |
axis.text.y = element_text(angle = 45, hjust = 1), | |
legend.position='bottom')+ | |
labs(fill='',x='',y='') + | |
guides(fill=guide_legend(nrow=2,byrow=TRUE)) + | |
scale_fill_manual(values=c('red','yellow','lightgreen','green')) | |
# all together | |
p <- | |
plot_grid(nrow=2, | |
p.b + ylab(''), | |
plot_grid(ncol=2, | |
p.d + theme(legend.position='none'), | |
p.byid | |
)) | |
print(p) | |
ggsave(p,file='hike1014_pref.png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment