r - Color mismatch using rgl -
i using rgl create scatterplot of points imported .csv dataset. colors i'd points set in dataset. works fine, except when scatterplot displayed colors of points not match colors defined in data. e.g., points designated "blue" might green, , points designated "yellow" might show red.
data=read.csv("explayout.csv", header = true) x=data$x y=data$y z=data$z color=data$color plot3d(x=x, y=y, z=z, type="s", col=color)
this due read.csv
converting strings factors
see difference in reproducible example
library(rgl) x<-1:5 y=1:5 z <- 1:5 colors <- c('red','green','blue','orange','purple') plot3d(x=x,y=y,z=z,col=colors, type = 's') colorsf <- factor(c('red','green','blue','orange','purple')) plot3d(x=x,y=y,z=z,col=colorsf, type = 's')
so, either read in color
character column using stringsasfactors=false
or coerce character using as.character()
or levels(colors)[colors]
Comments
Post a Comment