簡體   English   中英

ggiraph:修復了 geom_line_interactive 中的工具提示

[英]ggiraph: fixed tooltip in geom_line_interactive

我可能遺漏了一些非常非常明顯的東西......在示例 2 中,hovertext 顯示“1”,即分配的工具提示列的第一個值並且不會改變

我想要像示例 1 中那樣更改懸停文本,而不將 fe 顏色分配給 y(如示例 2 中所示)

  1. 顏色 = y
testdf <- data.frame(
  "x" = c(1:10),
  "y" = c(1:10))

test <- testdf %>% 
  ggplot2::ggplot() + 
  ggiraph::geom_line_interactive(
    ggplot2::aes(x = x,
                 y = y,
                 color = y,
                 tooltip = y)
  )

ggiraph::girafe(ggobj = test,
                height_svg = 3.5,
                options = list(
                  opts_sizing(rescale = T),
                  # Gestaltung des tooltips
                  opts_tooltip(css= "font-family: Helvetica; padding:3pt; color:white; background-color:#15253F; border-radius:5px"),
                  # Zoom
                  opts_zoom(max = 5),
                  # Hover Optionen 
                  opts_hover(css = "stroke-width:2;"),
                  opts_hover_inv(css = "opacity:0.8"),
                  opts_toolbar(position = "topright", saveaspng = F) 
                  
                ))
  1. 沒有顏色 = y
testdf <- data.frame(
  "x" = c(1:10),
  "y" = c(1:10))

test <- testdf %>% 
  ggplot2::ggplot() + 
  ggiraph::geom_line_interactive(
    ggplot2::aes(x = x,
                 y = y,
                 tooltip = x)
  )

ggiraph::girafe(ggobj = test,
                height_svg = 3.5,
                options = list(
                  opts_sizing(rescale = T),
                  # Gestaltung des tooltips
                  opts_tooltip(css= "font-family: Helvetica; padding:3pt; color:white; background-color:#15253F; border-radius:5px"),
                  # Zoom
                  opts_zoom(max = 5),
                  # Hover Optionen 
                  opts_hover(css = "stroke-width:2;"),
                  opts_hover_inv(css = "opacity:0.8"),
                  opts_toolbar(position = "topright", saveaspng = F) 
                  
                ))

一種解決方案是添加一個geom_point_interactive來表示這些值。 您可以通過使點非常小( size = 0.05 )來隱藏它們。

geom_point_interactive(aes(x = x,
             y = y,
             tooltip = x,
             data_id = x), size = 0.05)

表示 x 的值

如果您還想獲得有關整行的一些信息,可以將其添加為geom_line_interactive aes()中的不同變量,即tooltip = "My line"

geom_line_interactive(aes(x = x,
             y = y,
             tooltip = "My line",
             data_id = x)) +
geom_point_interactive(aes(x = x,
             y = y,
             tooltip = x,
             data_id = x), size = 0.05)

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM