简体   繁体   English

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

[英]ggiraph: fixed tooltip in geom_line_interactive

I'm probably missing something really, really obvious... In Example 2 the hovertext show '1', the first value of the assigned tooltip column and does not change我可能遗漏了一些非常非常明显的东西......在示例 2 中,hovertext 显示“1”,即分配的工具提示列的第一个值并且不会改变

I want to have a changing hover text like in example 1 without assinging fe color to y (like in example 2)我想要像示例 1 中那样更改悬停文本,而不将 fe 颜色分配给 y(如示例 2 中所示)

  1. with color = y颜色 = 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. Without color = y没有颜色 = 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) 
                  
                ))

One solution would be to add a geom_point_interactive to represent the values.一种解决方案是添加一个geom_point_interactive来表示这些值。 You can hide them by making the point very small ( size = 0.05 ).您可以通过使点非常小( size = 0.05 )来隐藏它们。

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

表示 x 的值

If you also want to have some information on the overall line, you can add this as a different variable in the geom_line_interactive aes() ie tooltip = "My line" :如果您还想获得有关整行的一些信息,可以将其添加为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