It’s 7pm Sunday April 26th, I rushed home from my hike eager to embark on my data challenge for the week. Oh, but little did I know that I would be spending the next two hours contemplating a series of philosophical questions, all while doubting my coding ability and career trajectory. How could a data challenge really put me through this turmoil?

Well, it first started with a simple question: what cities do I want to compare? Of course, I had the genius idea of picking four cities with the top PhD programs I’m considering applying to next fall, which induced just a bit of existential anxiety about my future.

But alas, I proceeded. Until, I read “a handful of cities” on our assignment guide. “A handful of cites” I thought… “Four is a handful, right?” Cue wasting 15 minutes Googling if a handful can be quantified, only to close my tabs no better off (well, except for a few yummy recipes that suggest a “a handful” of toppings).

Finally, I decided heck, I’m going to make four cities a handful. But, wait "I have to pick variables to measure the quality of life? Is this Philosophy or Advanced R?" I thought. Well, after 10 minutes, I realized I had to put away my philosophical musings and go with my gut or else my quality of life would soon be impacted by my self-induced anxiety from a 10 point data challenge.

So, onward we march past my should’ve been a loop or automated but I was too overwhelmed to even try after the above turmoil code.

variables_of_interest <- c("Cost of Living", "Leisure & Culture", "Healthcare") 

# Pittsburgh data 
res = GET("https://api.teleport.org/api/urban_areas/slug:pittsburgh/scores")
rawToChar(res$content)
pitt_data = fromJSON(rawToChar(res$content))
namevector <- c("city") 
pitt_data$categories[ ,namevector] <- "Pittsburgh"
pitt_final <- pitt_data$categories %>% 
   select(-color) %>% 
   filter(name %in% variables_of_interest) 
# Oxford data 
res = GET("https://api.teleport.org/api/urban_areas/slug:oxford/scores/")
rawToChar(res$content)
oxford_data = fromJSON(rawToChar(res$content))
namevector <- c("city") 
oxford_data$categories[ ,namevector] <- "Oxford"
oxford_final <- oxford_data$categories %>% 
   select(-color) %>% 
   filter(name %in% variables_of_interest) 
# SF data 
res = GET("https://api.teleport.org/api/urban_areas/slug:san-francisco-bay-area/scores/")
rawToChar(res$content)
sf_data = fromJSON(rawToChar(res$content))
namevector <- c("city") 
sf_data$categories[ ,namevector] <- "San Francisco / Bay Area"
sf_final <- sf_data$categories %>% 
   select(-color) %>% 
   filter(name %in% variables_of_interest) 
# Seattle data 
res = GET("https://api.teleport.org/api/urban_areas/slug:seattle/scores")
rawToChar(res$content)
seattle_data = fromJSON(rawToChar(res$content))
namevector <- c("city") 
seattle_data$categories[ ,namevector] <- "Seattle"
seattle_final <- seattle_data$categories %>% 
   select(-color) %>% 
   filter(name %in% variables_of_interest) 
grad_cities <- do.call("rbind", list(seattle_final, sf_final, oxford_final, pitt_final))
p1 <- ggplot(grad_cities, aes(x=as.factor(name), y=score_out_of_10, fill=as.factor(name))) +
  geom_bar(stat = "identity") + 
  scale_fill_hue(c = 40) +
  theme(legend.position="none") + 
  labs(title = 'City: {closest_state}', x = '', y = 'Score out of 10') + 
  transition_states(city, transition_length = 1, state_length = 1)  
animate(p1, nframes = 10, fps = 1)

So, we’ve made it this far. Are you tired yet? I am. Of course, now time to be objective about my metrics. Coming into this challenge, I wanted to find out which potential PhD city had the lowest cost of living and the top healthcare and culture and leisure. I had a hunch it would be Pittsburgh. But, I didn’t want my hunch to be right. Why? Well that’s a story for another time. But alas, internal conflict aside, it’s clear that Pittsburgh is the winner with the lowest cost of living and top health care and leisure and culture. Oh, and one more thing: I don’t think I actually answered the RQ for this challenge, but thanks for coming along on my journey!