TransWikia.com

Coloring labels using scatterplot3d in R

Data Science Asked by trolkura on April 3, 2021

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 3 categories : A , B , C.

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”, i.e. 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 collumn in dataset, but creating such array where:

length( colors ) = length( num of columns )

yields the same error.

What is the right way to add colors?

One Answer

For the colors argument you need to assign a vector with the same length as your data points.

You don't explain how colors must be assigned to values of your output columms . In any regard, this would assign 4 different colors randomly:

cols = sample(1:4, nrow(output), replace=TRUE) 

plot it with

scatterplot3d(output$X2,output$X6 , output$X7 , color=cols, pch=19, cex=1)

You could create a new column in your dataframe, e.g. rgbcolor and assign that:

scatterplot3d(output$X2,output$X6 , output$X7 , color=output$rgbcolor, pch=19, cex=1)

pch is the plotting character id, usually 1, 19 or 20 (circle or larger dot or smaller dot. (see for yourself: plot(1:25, 1:25, pch=1:25))

Tune the cex param to make it larger or smaller (1 means size = 100%)

Answered by knb on April 3, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP