如何解决在 r 中使用串扰 filter_select() 进行线图,但不在图中显示线
我正在尝试使用 rmarkdown
在 crosstalk
文档中获得交互性。
问题:当我使用串扰绘图时,它不会在图形中显示线条,但它给出悬停在绘图上的值。有没有办法在过滤器中设置默认选项?
代码:
library(tidyverse)
library(plotly)
library(crosstalk)
library(glue)
library(scales)
library(tidytext)
数据加载:
file_url <- "https://raw.githubusercontent.com/johnsNow09/covid19-df_stack-code/main/ts_all_long2.csv"
ts_all_long <- read.csv(url(file_url))
共享数据
confirm_col = "#32a4ba"
death_col = "#f08080"
Country_selected = c("United Kingdom")
dual_axis_plt_data <- ts_all_long %>%
group_by(Country.Region) %>%
mutate(scaleFactor = max(Confirmed_daily) / max(Death_daily)) %>%
ungroup() %>%
SharedData$new()
ggplotly()
dual_axis_plt <- ggplotly(
ggplot(data = dual_axis_plt_data,aes(x = date)) +
geom_area(aes(y = Confirmed_daily),fill = confirm_col,alpha = .7) +
geom_line(aes(y = Death_daily * scaleFactor),col = death_col,size = 0.8,alpha = 0.8) +
scale_y_continuous(name = "Daily Cases",sec.axis = sec_axis(~./scaleFactor,name = "Daily Deaths"),labels = scales::comma_format()) +
scale_x_date(date_breaks = "1 month",date_labels = "%b") +
theme_excel_new() +
theme(
axis.title.y.left=element_text(color=confirm_col),axis.text.y.left=element_text(color=confirm_col),axis.title.y.right=element_text(color=death_col),axis.text.y.right=element_text(color=death_col),plot.title = element_markdown(face = "plain",family = "serif",size = 14),panel.grid.major = element_blank()
) +
labs(title = glue("<i>{Country_selected}</i>: Daily confirmed & death cases as of: {max(ts_all_long$date)}"),caption = "Data source: covid19.analytics)
)
bscols(widths = c(3,9),list(
filter_select(id = "country",label = "Country",sharedData = dual_axis_plt_data,group = ~Country.Region)
),dual_axis_plt)
预期结果:
没有串扰交互它看起来像这样(它是一个双轴图):
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。