R Plotly:parcoords 图中的错误

R Plotly: Bugs in parcoords plot

我在使用 parcoords 图时在 R 中使用 plotly 时遇到了非常奇怪的错误。

例如,使用此处提供的示例:https://plot.ly/r/parallel-coordinates-plot/

library(plotly)

df <- read.csv("https://raw.githubusercontent.com/bcdunbar/datasets/master/iris.csv")

df %>%
  plot_ly(type = 'parcoords',
          line = list(color = ~species_id,
                      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)
            )
          )

此图的结果:

这是全图,右边的图我没有裁剪。如果我四处移动轴,数据会闪烁,通常 RStudio 会崩溃。这是我的会话信息:

> sessionInfo()

R version 3.4.1 (2017-06-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=German_Switzerland.1252  LC_CTYPE=German_Switzerland.1252    LC_MONETARY=German_Switzerland.1252
[4] LC_NUMERIC=C                        LC_TIME=German_Switzerland.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_3.4.1 tools_3.4.1   

和我的 plotly 版本:

> packageVersion('plotly')
[1] ‘4.7.1’

有没有人遇到同样的问题?有针对这个的解决方法吗?

问题出在Rstudio的查看器上。
我建议在您的代码中添加 options(viewer=NULL)
它会禁用 RStudio 的内部查看器并在浏览器中打开您的绘图。

library(plotly)

options(viewer=NULL) 

df <- read.csv("https://raw.githubusercontent.com/bcdunbar/datasets/master/iris.csv")   
p <- df %>%
  plot_ly(type = 'parcoords',
          line = list(color = ~species_id,
                      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)
          )
   )
print(p)