我有一个可视化(见下文),它具有很好的悬停功能,使可读性更容易。我希望用户能够通过单击他们悬停的东西来使悬停功能持续存在。这可以使用ggiraph
吗?
最小的可重现示例代码:
library(tidyverse)
library(ggiraph)
nodes = tibble(value=c(1,2,1,2), week=c(1,1,2,2))
vertices = tibble(From=c(1,1,2,2), To=c(1,2,1,2), weight=c(.5,.5,.5,.5), start_week=1, rand=c(.48, .33, .34,.40))
p=ggplot(nodes) +
geom_point_interactive(size = 12, aes(x=week, y=value, color =paste(week, value), data_id=paste(week, value)))+
geom_text_interactive(color="white",aes(x=week, y=value, label=value, data_id=paste(week, value)))+
geom_segment_interactive(data=vertices, aes(x=start_week+.1, xend=start_week+1-.1, y=From, yend=To,
data_id=paste(start_week, From)))+
geom_text_interactive(data=vertices, aes(x=start_week+rand, y=From-(From-To)*rand, label=paste0(round(weight*100), "%"),
data_id=paste(start_week, From)), vjust=-.1, hjust=-.1) +
guides(color=F, size=F)+
scale_y_continuous(name="Cluster", breaks=NULL, labels=NULL)+
scale_x_continuous(name="Stage", breaks=1:6)+
theme_minimal()
girafe(ggobj=p,
options = list(
opts_hover_inv(css = "opacity:0.1;"),
opts_hover(css = "stroke-width:2;")
))