library(tidyverse)
library(httr)
library(jsonlite)
library(ggpubr)
As a native of Los Angeles and going to college in San Luis Obispo, I decided to explore the difference in quality of life between these two cities. I predict that Los Angeles is going to have a higher average salary than San Luis Obispo; however, I am unsure and curious as to how their scores on certain aspects of life will differ.
#LA Score
LA_score <- GET("https://api.teleport.org/api/urban_areas/slug:los-angeles/scores/")
LA_score_data <- fromJSON(rawToChar(LA_score$content))
LA_categories <- LA_score_data$categories %>%
select(name, score_out_of_10) %>%
rename("Category" = name,
"Score" = score_out_of_10)
#LA Salaries
LA_salary <- GET("https://api.teleport.org/api/urban_areas/slug:los-angeles/salaries/")
LA_salary_data <- fromJSON(rawToChar(LA_salary$content))
LA_jobs <- LA_salary_data$salaries$job %>%
select(title)
LA_sals <- LA_salary_data$salaries$salary_percentiles
LA_med_sals <- data.frame(LA_sals$percentile_50)
LA_salaries <- cbind(LA_jobs, LA_med_sals) %>%
rename("Job" = title,
"Median_sal" = LA_sals.percentile_50) %>%
mutate(City = "LA")
#SLO Score
SLO_score <- GET("https://api.teleport.org/api/urban_areas/slug:san-luis-obispo/scores/")
SLO_score_data <- fromJSON(rawToChar(SLO_score$content))
SLO_categories <- SLO_score_data$categories %>%
select(name, score_out_of_10) %>%
rename("Category" = name,
"Score" = score_out_of_10)
#SLO Salaries
SLO_salary <- GET("https://api.teleport.org/api/urban_areas/slug:san-luis-obispo/salaries/")
SLO_salary_data <- fromJSON(rawToChar(SLO_salary$content))
SLO_jobs <- SLO_salary_data$salaries$job %>%
select(title)
SLO_sals <- SLO_salary_data$salaries$salary_percentiles
SLO_med_sals <- data.frame(SLO_sals$percentile_50)
SLO_salaries <- cbind(SLO_jobs, SLO_med_sals) %>%
rename("Job" = title,
"Median_sal" = SLO_sals.percentile_50) %>%
mutate(City = "SLO")
sals <- rbind(LA_salaries, SLO_salaries)
score <- merge(LA_categories, SLO_categories, by = "Category") %>%
rename("LA_Score" = Score.x,
"SLO_Score" = Score.y)
#comparing salary plot
s <- ggplot(sals, aes(Median_sal, fill = City)) +
geom_density(alpha = 0.5) +
labs(title = "Median Salaries of Jobs in LA vs. SLO",
x = "Median Salary ($)")+
theme(axis.title.y = element_blank(),
axis.text.y = element_blank(),
axis.ticks.y = element_blank()) +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank(),
axis.line = element_line(colour = "black")) +
scale_fill_manual(values=c("blue4", "darksalmon"))
#comparing score plot
q <- ggplot(score) +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank(),
axis.line = element_line(colour = "black")) +
theme(axis.title = element_blank(),
axis.ticks.y = element_blank(),
axis.line = element_blank()) +
geom_point(aes(x = 12, y = Category),
size = 0, col = "white") +
geom_hline(yintercept = 1:17, col = "grey80") +
geom_point(aes(x = LA_Score, y = Category),
size = 7, col = "blue4") +
geom_point(aes(x = SLO_Score, y = Category),
size = 7, col = "darksalmon") +
geom_text(size = 3.2, aes(x = LA_Score, y = Category,
label = paste0(round(LA_Score,1))),
col = "white") +
geom_text(size = 3.2, aes(x = SLO_Score, y = Category,
label = paste0(round(SLO_Score,1))),
col = "black") +
scale_x_continuous(breaks = c(0, 2, 4, 6, 8, 10),
labels = c("0", "2", "4", "6", "8", "10")) +
scale_y_discrete(expand = c(0.05, 0)) +
labs(title = "Quality of Life in LA vs. SLO")
Below, I created an overlapping density plot to easily visualize the difference between median salaries in these two cities. Moreover, I created a horizontal dot plot to display the scores that each city was given about certain aspects.
ggarrange(s, q, nrow = 1, hjust = -5)
In conclusion, Los Angeles has a much higher median salary than San Luis Obispo as I expected. San Luis Obispo’s average median salary was around $40,000 while Los Angeles had an average median salary of closer to $70,000. Regarding the scores on aspects of life. They differ quite a lot in most categories. Each city possesses their own negative qualities that drive people away; however, they both also contain positive qualities that make them desirable.