在使用plotly
情节时,R
使用parcoords
时,我遇到了非常奇怪的错误。
例如,使用此处提供的示例: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:
> 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’
有人遇到同样的问题吗?这个问题有方法解决吗?
答案 0 :(得分:3)
问题在于Rstudio的观众
我建议您在代码中添加let dataset = d3.layout.stack()(['value1', 'value2',
'value3'].map((value) => {
return data.map((d: any) => {
return { x: obj[d.xAxis], y: d.value };
});
}));
let x = d3.scale.ordinal()
.domain(dataset[0].map((d) => { return d.x; }))
.rangeBands([0, width], 1);
let y = d3.scale.linear()
.domain([0, d3.max(dataset, (d) => {
return d3.max(d, (d1) => { return d1.y0 + d1.y; });
})])
.range([height, 0]);
。
它会禁用RStudio的内部查看器并在浏览器中打开您的情节。
options(viewer=NULL)