r - 第二条线图未按应有的方式绘制
问题描述
我正在使用闪亮的基于数据框中的一个字段(市政名称)绘制两个折线图,但是当我更改市政名称时,第二个(报告的黑色案例)没有按照应有的方式绘制,它只是一条平线,不知道我做错了什么
xx < -left_join(cases_pop_normalised, df_rna_inhab, by = c("Municipality_name" = "municipality_name"))
ui < -fluidPage(titlePanel(h2("Blood Test Result System", align = "center")),
sidebarLayout(
sidebarPanel(
selectInput(inputId = "dataset",
label = "Choose a municipality:",
choices = sort(x = names(table(unique(xx$Municipality_name)))),
selected = "Westland")),
mainPanel(
plotOutput("ts_plot"),
verbatimTextOutput("summary"))))
server < -shinyServer( function (input, output) {
datasetInput < -reactive({
xx < -left_join(cases_pop_normalised, df_rna_inhab, by = c("Municipality_name" = "municipality_name")) % > %
filter(Municipality_name == input$dataset) % > %
distinct()
})
})
cases_pop_normalised$Date_of_publication < -as.Date(cases_pop_normalised$Date_of_publication)
df_rna_inhab$newDate < -as.Date(df_rna_inhab$newDate)
# plot time series
output$ts_plot < -renderPlot({
wastewaterColor < -"red"
dataset < -datasetInput()
dataset$Date_of_publication < -as.Date(dataset$Date_of_publication)
ggplot() +
geom_line(data = dataset, aes(x = newDate, y = RNA_flow_per_100000), size = 1, color = wastewaterColor) +
geom_line(data = dataset, aes(x = Date_of_publication, y = as.numeric(reported_norm)), size = 1, color = black) + ###NOT PLOTTING PROPERLY
scale_y_continuous(
name = "Reported cases",
sec.axis = sec_axis(~., name = "Wastewater")
) +
theme_ipsum() +
theme(axis.text.x = element_text(angle = 45, vjust = 0.5, hjust = 1),
axis.title.y = element_text(color = MortalityColor, size = 10),
axis.title.y.right = element_text(color = wastewaterColor, size = 10)
) +
labs(x = "Date") +
ggtitle("test")
})
})
app < -shinyApp(ui = ui, server = server)
这是数据的子集
Date_of_publication Municipality_name reported_norm RNA_value newDate RNA_flow_per_100000
10/24/2020 Westland 92.41223 2.16E+14 1/4/2021 1.08E+14
10/24/2020 Westland 92.41223 2.54E+14 1/12/2021 8.09E+13
10/15/2020 Aalten 84.80513 3.71E+12 9/9/2020 1.67E+12
10/25/2020 Westland 84.25821 0 9/7/2020 0
10/22/2020 Westland 78.8222 2.54E+14 1/12/2021 8.09E+13
10/18/2020 Aalten 80.80513 5.71E+12 9/9/2020 1.67E+12
解决方案
推荐阅读
- flutter - 使用 PC 屏幕 Chrome 在 Android 上运行
- javascript - 为什么useEffect不更新元素删除状态
- flutter - 在 Flutter 中使用 InAppWebview 未显示全部内容
- javascript - 如何从html将参数传递给打字稿函数?
- javascript - 多个包含在一个模型中查询
- python - 如何使用熊猫 convert_dtypes()?
- wordpress - 使用高级自定义字段中继器字段显示三列 Bootstrap 图像网格
- variables - 如何为 service_facts 声明一个变量
- c++ - 运行 NI-IMAQ 和 WINAPI 需要 2 个不同的子系统
- docker - 空手道:UI - Jenkins 集成