此部分為EMOC資料分析程式碼,主要分析內容為:
轉診人數疊層直條圖(依據檢傷級數;依據年份)
轉診人數折線圖(依據年份)
匯入資料
EMOC_v7(EMOC最新版本資料)
匯入套件
library(reshape2)
library(plyr)
library(ggplot2)
library(gridExtra)
移除“排除”欄位中排除的資料
EMOC_v7$排除[EMOC_v7$排除 != "排除"] <- NA
EMOC_v7_Kaoshiung <- subset(EMOC_v7, (is.na(EMOC_v7[,"排除"])))
移除“轉出醫院名稱”欄位中“義大”及“義大癌治療醫院”的資料
因為此兩家醫院轉院特性與其他醫院不同,暫不加入分析
EMOC_v7_Kaoshiung_remove <- EMOC_v7_Kaoshiung[which(EMOC_v7_Kaoshiung$EMOC轉出醫院名稱 != "義大"
& EMOC_v7_Kaoshiung$EMOC轉出醫院名稱 !=
"義大癌治療醫院"), ]
圖表使用資料處理
prop_EMOC_v7_Kaoshiung_remove_year <- melt(table(EMOC_v7_Kaoshiung_remove$轉診型態, EMOC_v7_Kaoshiung_remove$檢傷級數分類, EMOC_v7_Kaoshiung_remove$年份))
prop_EMOC_v7_Kaoshiung_remove_year <- ddply(prop_EMOC_v7_Kaoshiung_remove_year,.(Var3,
Var2),transform,prop=value/sum(value))
prop_EMOC_v7_Kaoshiung_remove_year$Var1 <- revalue(prop_EMOC_v7_Kaoshiung_remove_year$Var1,
c("上轉"="上轉"))
prop_EMOC_v7_Kaoshiung_remove_year$Var1 <- revalue(prop_EMOC_v7_Kaoshiung_remove_year$Var1,
c("下轉"="下轉"))
prop_EMOC_v7_Kaoshiung_remove_year$Var1 <- revalue(prop_EMOC_v7_Kaoshiung_remove_year$Var1,
c("平轉"="平轉"))
bar_combine<- ggplot(data = EMOC_v7_Kaoshiung_remove, aes(x = EMOC_v7_Kaoshiung_remove$檢傷級數分類)) +
geom_bar(aes(fill = EMOC_v7_Kaoshiung_remove$轉診型態)) +
scale_fill_discrete(name = "轉診型態") +
ggtitle("轉診人數 (Overall)") +
theme(plot.title = element_text(hjust = 0.5, size = 18, face = "bold")) +
xlab("檢傷級數分類")
bar_year_combine<- ggplot(data = EMOC_v7_Kaoshiung_remove, aes(x = EMOC_v7_Kaoshiung_remove$檢傷級數分類)) +
geom_bar(aes(fill = EMOC_v7_Kaoshiung_remove$轉診型態)) +
facet_wrap(~年份) +
scale_fill_discrete(name = "轉診型態") +
ggtitle("轉診人數 (年份)") +
theme(plot.title = element_text(hjust = 0.5, size = 18, face = "bold")) +
xlab("檢傷級數分類")
grid.arrange(bar_combine, bar_year_combine, ncol=2)
ggplot(prop_EMOC_v7_Kaoshiung_remove_year, aes(as.factor(Var3), prop , group = Var1, colour = Var1)) + facet_wrap(~Var2) +
coord_cartesian(ylim=c(0, 1)) +
geom_point(size = 4.2, shape = 21, fill = "white") +
geom_line(size = 1.3) +
ggtitle("檢傷級數分類") +
theme(plot.title = element_text(hjust = 0.5, size = 18, face = "bold")) +
scale_color_discrete("轉診型態") +
xlab("轉診年份")