返回在散点图中选择的数据点 [英] Return datapoints selected in a plotly scatterplot

查看:117
本文介绍了返回在散点图中选择的数据点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ggplotly从ggplot2创建了一个散点图.

I created a plotly scatterplot from a ggplot2 using ggplotly.

我想获得一个选定/放大的数据点的表,但是我找不到解决方法.

I would like to obtain a table of the datapoints selected / zoomed into, but I can't find a way to do this.

library(ggplot2)
library(plotly)

p <- ggplotly(plot.rel.kinship)
htmlwidgets::saveWidget(as_widget(p), "scatterplot.html")

在密谋论坛上似乎有一个类似的未解决问题:

There seems to be a similar unanswered question on the plotly forum:

https://community.plot.ly /t/get-datapoints-in-currently-zoomed-view/259

这个问题似乎也与之有关:

This question also seems to be related:

通过Shiny中的串扰与DT配合使用

谢谢您的帮助.

更新:

library(crosstalk)

a <- datatable(king.kin.subset)

kinship.plotly.table <- bscols(widths = c(6, 4), p, a)

htmltools::save_html(kinship.plotly.table, "scatterplot_table.html")

仍然无法根据散点图上的点选择来更新数据表.

Still cannot manage to update the DataTable based on the selection of points on the scatterplot.

推荐答案

plotly文档中,它说可以使用crosstalk链接不带shiny的视图.您没有提供可重复的示例,因此这里是使用iris数据集的示例.您可以尝试:

In the plotlydocumentation it says it possible to link views without shiny, using crosstalk. You did not provide a reproducible example so here is an example using the iris dataset. You could try:

library(plotly)
library(crosstalk)
library(DT)


sd <- SharedData$new(iris)

a <- plot_ly(sd, x = ~Sepal.Width, y = ~Petal.Width) %>% 
  add_markers(alpha = 0.5) %>%
  highlight("plotly_selected", dynamic = TRUE)


options(persistent = TRUE)

p <- datatable(sd)

bscols(widths = c(6, 4), a, p)

plotly在开发版本中具有table,但我无法在上面的示例中弄清楚如何使用它. DT比较容易,但是您可以使它工作.希望对您有所帮助.

plotlyhas in the development version a tablebut I could not figure out how to use it with the example above. DTwas easier but you might be able to make it work. Hope it helps.

使用ggplotly,您可以尝试以下操作:

With ggplotly, you can try this:

d <- highlight_unit(iris)
a <- ggplotly(ggplot(data = d, aes(x = Sepal.Width, y = Petal.Width)) + geom_point()) %>%
  highlight("plotly_selected", dynamic = TRUE)

options(persistent = TRUE)

p <- datatable(d)

bscols(widths = c(6, 4), a, p)

这篇关于返回在散点图中选择的数据点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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