[英]set css property separately for each layer on hover (ggiraph)
使用ggiraph
,我想使用 hover 为每个ggplot
geom_
或层设置不同的 ZC7A62 css
属性。 在下面的示例中,如何在 hover 上将第二个geom_rect_interactive
的笔触设置为蓝色,但在 hover 上将第一层笔触保持为红色(保持data_id
相同,以便两者都响应悬停在任一层上)?
library(ggplot2)
library(ggiraph)
p <-
ggplot(
data = data.frame(id = seq(3), x = 1:3, y = 1:3)
) +
# red stroke
geom_rect_interactive(
mapping = aes(
xmin = x, xmax = x - 0.1,
ymin = y, ymax = y - 0.1,
data_id = id
)
) +
# blue stroke
geom_rect_interactive(
mapping = aes(
xmin = x, xmax = x + 0.1,
ymin = y, ymax = y + 0.1,
data_id = id
)
)
x <- girafe(ggobj = p)
x <- girafe_options(
x,
opts_hover(
css = "stroke:#ff0000;"
)
)
x
我猜我可能能够做一些事情,比如将一些自定义css
8CBA22E28EB17B5F5C6AE2A266AZ class 分配给特定层(例如, .mystroke {stroke:#0000ff;}
),但不知道如何处理这个问题。
(我是作者之一)这目前是不可能的,我们还没有考虑过这种情况(如果我们可以实现它,我们会考虑)。
目前,只能为每种形状类型指定 CSS。 一个例子会更有意义,它复制自:
https://davidgohel.github.io/ggiraph/articles/offcran/customizing.html#detailled-control-1
library(ggplot2)
library(ggiraph)
dataset <- mtcars
dataset$carname <- row.names(dataset)
gg_scatter <- ggplot(dataset, aes(x = disp, y = qsec, label = carname,
data_id = carname, color= wt) ) +
geom_point_interactive(size=3) +
geom_text_interactive(vjust = 2) +
theme_minimal()
girafe(ggobj = gg_scatter2,
options = list(
opts_hover(
css = girafe_css(
css = "fill:purple;stroke:black;",
text = "stroke:none;fill:red;"
)
)
) )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.