R:绘图未完全加载加载

由网友(冷瞳づ)分享简介:我正在使用 R 编程语言.我正在尝试在此处遵循本教程:有谁知道为什么这两个情节不同,我该如何解决这个问题?谢谢 解决方案 本教程中使用的数据有一个附加列 species_id,它是每个物种唯一的整数列.默认的 iris 数据集没有,因此您可以将作为因子的 Species 列转换为整数.图书馆(情节)虹膜 %>% plo...

我正在使用 R 编程语言.我正在尝试在此处遵循本教程:

有谁知道为什么这两个情节不同,我该如何解决这个问题?谢谢

解决方案 Instagram完全加载不出照片

本教程中使用的数据有一个附加列 species_id,它是每个物种唯一的整数列.默认的 iris 数据集没有,因此您可以将作为因子的 Species 列转换为整数.

图书馆(情节)虹膜 %>% plot_ly(type = 'parcoords', line = list(color = ~as.integer(Species),colorscale = list(c(0,'red'),c(0.5,'green'),c(1,'blue'))),尺寸=列表(列表(范围= c(2,4.5),标签='萼片宽度',值=〜Sepal.Width),列表(范围 = c(4,8),约束范围 = c(5,6),标签 = '萼片长度',值 = ~Sepal.Length),列表(范围 = c(0,2.5),标签 = '花瓣宽度',值 = ~Petal.Width),list(range = c(1,7), label = 'Petal Length', values = ~Petal.Length) ) )

I am working the R programming language. I am trying to follow this tutorial over here: https://plotly.com/r/parallel-coordinates-plot/

I am trying to make a "parallel coordinate plot" of the famous iris data set.

Instead of loading the iris data set through the github link, I tried to use the built in iris data set that is available in R:

#load library
library(plotly)

#load data
data(iris)
df = iris


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

#view plot
fig

However, this produces an incomplete plot:

Does anyone know why these two plots are different and how can I fix this? Thanks

解决方案

The data used in the tutorial has an additional column species_id which is an integer column unique for every species. The default iris dataset does not have that so you can convert the Species column which is factor to integer.

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) ) )  

阅读全文

相关推荐

最新文章