R:添加“工具提示";到互动情节(情节) [英] R: Adding a "tool tip" to interactive plot (plotly)

查看:22
本文介绍了R:添加“工具提示";到互动情节(情节)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 R 编程语言.从上一篇文章(

假设我要添加一个id";列到数据集,例如

库(dplyr)df <- iris %>% mutate(id = row_number())

有没有可能,当你点击"时在任何线路"上在这个图上,出现了与该行对应的数据集(即df")的信息?

谢谢

解决方案

没有运行你的代码,但你可能需要事先将所有文本准备为一个字符串在列中,并使用 text = ~tooltip_column 显示它.它可能与 一起用于行拆分

 图 <- plot_ly(类型 = 'scatter3D',x = -calcDataMeas2$pos_X,y = calcDataMeas2$pos_Y,z = z_value,文本 = calcDataMeas2$tube_name,场景='场景1',模式='标记',标记 = 标记)

I am using the R programming language. From a previous post (R: Plot not Fully Loading), I learned how to make interactive plots in R using plotly :

library(plotly)

iris %>% plot_ly(type = 'parcoords', line = list(color = ~as.integer(Species), 
         colorscale = list(c(0,'red'),c(0.5,'green'),c(1,'blue'))), 
         dimensions = list( list(range = c(2,4.5), label = 'Sepal Width', values = ~Sepal.Width), 
                      list(range = c(4,8), constraintrange = c(5,6), label = 'Sepal Length', values = ~Sepal.Length), 
                      list(range = c(0,2.5), label = 'Petal Width', values = ~Petal.Width), 
                      list(range = c(1,7), label = 'Petal Length', values = ~Petal.Length) ) )  

Suppose if I was to add an "id" column to the data set, e.g.

library(dplyr)
df <- iris %>% mutate(id = row_number())

Is it possible so that when you "click" on any of the "lines" on this plot, information from the dataset (i.e. "df") corresponding to row of that line appears?

Thanks

解决方案

Did not run your code, but you may need to prepare all the text as one string in the column beforehand and use text = ~tooltip_column to display it. It may work with for line splits

  fig <- plot_ly(
    type = 'scatter3D',
    x = -calcDataMeas2$pos_X,
    y = calcDataMeas2$pos_Y,
    z = z_value,
    text = calcDataMeas2$tube_name,
    scene = 'scene1',
    mode = 'markers',
    marker = marker
  )

这篇关于R:添加“工具提示";到互动情节(情节)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆