【发布时间】:2020-12-02 16:05:04
【问题描述】:
大家好,我有这样的医院数据;
hospitals <- c('Johnd Hospital','Johnd Hospital','Jolie Hope Hospital','Jolie Hope Hospital','Hope Hospital','Hope Hospital')
variables <- c('temperature', 'temperature', 'pulse rate','pulse rate', 'resp rate', 'resp rate')
score <- c(92,82,63,78, 23, 59)
months <- c('october', 'september', 'october', 'september', 'october', 'september')
datat <- data.frame(hospitals, variables, score, months)
datat$colour <- ifelse(datat$score >=90, "seagreen3",
ifelse(datat$score > 80 & datat$score <= 89, "gold1",
ifelse(datat$score > 60 & datat$score <= 79, "plum2", "red3")))
#performance scores
datat$perfomance <- ifelse(as.numeric(datat$score) >=90, "Excellent Perfomance (>=90)%",
ifelse(as.numeric(datat$score) >= 80 & as.numeric(datat$score) <= 89, "Good Perfomance (80-89)%",
ifelse(as.numeric(datat$score) > 60 & as.numeric(datat$score) <= 79, "Some Perfomance (60-79)%", "Poor Perfomance (<60)%")))
nam = c("Good Perfomance (80-89)%", "Some Perfomance (60-79)%", "Poor Perfomance (<60)%", "Excellent Perfomance (>=90)%")
grays = c("gold1", "plum2", "red3", "seagreen3")
my_color <- setNames(grays, nam)
my_color
现在这个数据我想绘制当月和上月的变量性能。到目前为止,我能够可视化当前月份和上个月的可变分数的闪避条形图。一个例子是一个变量,比如温度,这个月和上个月我有两个条形图。 这是我的可视化方式
myplott <- function(datat, hospital) {
print(paste0("Plot for hospital: ", hospital))
p <- ggplot(datat%>% filter(hospitals == hospital),
aes(x = variables, y = as.numeric(score))) +
#facet_grid(cols = vars(Group), scales = "free", space = "free") +
geom_bar(position = "dodge2", stat = "identity") +
theme_bw() +
ylab("Percentage %") +
scale_y_continuous(breaks = seq(-10, 100, by = 10)) +
ggtitle(hospital) +
labs(caption = "Please note; -5 (red paint below 0) indicates 0% documentation for that indicator") +
### use manual color here
scale_fill_manual(values = my_color) +
theme(axis.text.x = element_text(size = 13, hjust = 1, angle = 45)) +
geom_hline(yintercept = 90, linetype = "dashed", color = "black", size = 0.5) +
geom_hline(yintercept = 80, linetype = "dashed", color = "black", size = 0.5) +
geom_hline(yintercept = 60, linetype = "dashed", color = "black", size = 0.5) +
geom_hline(yintercept = 0, linetype = "dashed", color = "black", size = 0.5) +
#geom_text(aes(label = value), vjust = 0, color = "black", size = 2.8) +
theme(plot.title = element_text(face = "bold", hjust = 0.5, size = 20), legend.position = "top") +
#theme(plot.subtitle.title = element_text('Admission and during admission vitals monitored')) +
theme(legend.title = element_blank())
return(p)
}
myplott(comb.data, "Jolie Hope Hospital")
我现在的难题是如何命名 X 轴上的条形图,以便人们可以知道上个月和当前月的条形图,例如将 temperature 命名为 temperature(october) 和 温度(11 月)。最终结果是在 X 轴上重命名当前月份和上个月的变量分数。如果有人知道我如何命名 X 轴上的条形,请提供帮助。谢谢
【问题讨论】: