【发布时间】:2019-10-11 20:32:30
【问题描述】:
对于 R 或任何编程来说还是很新的东西,向部门展示一些健康结果数据,我想我会尝试写一些东西来让我选择要显示的数据子集。完成了一些自主阅读并尝试了以下内容(请参见下文)。
我遇到的问题是,当我选择所有 4 种“手术方法”时,得到的结果不是我所期望的。例如,2019 年 7 月的平均 LOS 应该低于我在此处看到的。
正如我所说,对此非常陌生,请假设我在回答这个问题时一无所知。
# User Interface
ui <-basicPage(
sliderInput("year", "Select Year:", animate = T,
min = 2016, max = 2019, value = 2016, sep = ""),
checkboxGroupInput("approach", "Surgical Approach", c("Laparoscopic", "Lap-assisted", "Converted to open", "Open"),
selected = c("Laparoscopic", "Lap-assisted", "Converted to open", "Open")),
plotOutput(outputId = "LOS_plot"),
plotOutput(outputId = "All3_plot")
)
# Server
server <- function(input, output){
output$LOS_plot <- renderPlot({
ERAS %>% filter(Sx_Approach == input$approach) %>%
arrange(year_m) %>%
mutate(DoSdate = ymd(year_m), yearDoS = year(DoSdate), monthDoS = month(DoSdate)) %>%
filter(yearDoS == input$year) %>%
group_by(year_m) %>% mutate(mean_LOS = mean(Postop_LOS)) %>%
ggplot(aes(x = monthDoS, y = mean_LOS)) + geom_line(colour = "black", size = 1.5) +
scale_x_continuous(limits = c(1, 12), breaks = c(1:12)) +
scale_y_continuous(limits = c(0, 30), minor_breaks = 1) +
theme(aspect.ratio = 0.4) + xlab("Month") + ylab("Days") + ggtitle("Mean Length of Stay over Time")
})
output$All3_plot <- renderPlot({
ERAS %>% filter(Sx_Approach == input$approach) %>%
arrange(year_m) %>%
mutate(DoSdate = ymd(year_m), yearDoS = year(DoSdate), monthDoS = month(DoSdate)) %>%
filter(yearDoS == input$year) %>%
group_by(year_m) %>% mutate(mean_All3 = mean(All_3 == T, na.rm = T)) %>%
ggplot(aes(x = monthDoS, y = mean_All3)) + geom_line(colour = "#5391c6", size = 1.5) + scale_x_continuous(limits = c(1, 12), breaks = c(1:12)) +
scale_y_continuous(labels = scales::percent, limits = c(0, 1)) +
theme(aspect.ratio = 0.4) + xlab("Month") + ylab("Percentage") + ggtitle("Patients Achieving All Three ERAS Goals")
})
}
【问题讨论】: