我尝试同时用鼠标悬停显示每年的多个信息。
像这样: 在此处输入图像描述
有任何想法吗?
数据
structure(list(Value = c(6.95e+08, 3.77e+08, 1.495e+09, 6.15e+08,
2.478e+09, 1.133e+09, 3.181e+09, 8.1e+08), Year = c(2007L, 2007L,
2008L, 2008L, 2009L, 2009L, 2010L, 2010L), Parent.0 = c("be0d29e1",
"5125b809", "be0d29e1", "5125b809", "be0d29e1", "5125b809", "be0d29e1",
"5125b809"), Value.YoY = c(NA, NA, 1.15107913669065, 0.631299734748011,
0.65752508361204, 0.842276422764228, 0.283696529459241, -0.285083848190644
), Value.YoY.perc = c(NA, NA, "115.11%", "63.13%", "65.75%",
"84.23%", "28.37%", "-28.51%")), class = c("grouped_df", "tbl_df",
"tbl", "data.frame"), row.names = c(NA, -8L), groups = structure(list(
Parent.0 = c("5125b809", "be0d29e1"), .rows = structure(list(
c(2L, 4L, 6L, 8L), c(1L, 3L, 5L, 7L)), ptype = integer(0), class = c("vctrs_list_of",
"vctrs_vctr", "list"))), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -2L), .drop = TRUE))
编码:
p <-ggplot(data, aes(x= Year,y=Value.YoY, fill=Parent.0)) +
geom_bar_interactive(position="dodge",
stat = "identity",
color = "black",aes(
tooltip = paste0(round(Value.YoY,2)*100," %","\n",
Year),data_id = Year))+
facet_grid(cols=vars(Parent.0), scales = "free", labeller = labeller(Parent.0 = label_wrap_gen(width=20)))
girafe(ggobj = p)