简体   繁体   中英

Coloring data in scatterplot 3d in r

I am trying to visualize data using R and scatterplot3d.

I have loaded data and used

colors <- c("#999999", "#E69F00", "#56B4E9" )
scatterplot3d(output$X2,output$X6 , output$X7 , color=colors, pch="X9")

X9 is label column in my dataset. it contains categories eg "ab" , "cpu" , "imdb" and so on.

By documentation:

color : colors of points in the plot, optional if x is an appropriate structure. Will be ignored if highlight.3d = TRUE.

pch: plotting "character", ie symbol to use.

Yet I still get this error

Error in scatterplot3d(output$X2, output$X6, output$X7, color = colors, : length(color) must be equal length(x) or 1

I assumed I had to put color for every column in dataset , but creating such array where length( colors ) = length(num of columns) yields same error.

What is the right way to add colors?

Thanks for help.

You have fewer colors than data points. You must select one color for each point. Since X9 seems to be a string, you can use as.factor to assign a unique number to each value.

scatterplot3d(output$X2,output$X6 , output$X7 , color=colors[as.factor(output$X9)], pch=20)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM