[英]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.