install.packages("RColorBrewer")
install.packages("plotly")
library(plotly)
library(RColorBrewer)
# city_name 기준으로 pop과 hosp 병합
merged_data <- merge(pop, hosp, by = "city_name", all = TRUE)
# NA 값 제거
merged_data <- merged_data[!is.na(merged_data$phys_total) & !is.na(merged_data$city_name), ]
# 도시별 의사 수 합계 계산
city_phys_totals <- tapply(merged_data$phys_total, merged_data$city_name, sum)
city_phys_totals
# 컬러 추가 (12개 이상의 컬러)
colors <- colorRampPalette(brewer.pal(12, "Set3"))(length(city_phys_totals))
# plotly 사용하여 막대 그래프
fig <- plot_ly(
x = names(city_phys_totals),
y = as.numeric(city_phys_totals),
type = 'bar',
marker = list(color = colors)
)
fig