I am relatively new to R. I am trying to plot a 3D scatterplot. I have 4 continuous variables, one of which defines the group. There are 6 groups.
I tried this code:
scatterplot3d(x,y,z,color=as.numeric(group),pch=20)
The colors are all too similar. How can I assign specific colors to the 6 groups?
Could you also tell me how to change the font to Calibri?
Thank you so much! :)
Asked
Active
Viewed 946 times
0
Sweezy
- 1
1 Answers
0
For the font part, I'll refer you to this answer, which addresses it very well.
For the color part, you have to set up a color palette, and then use your numeric group variable to access the different colors in the palette.
e.g
# make some dummy data
group <- factor(rep(letters[1:3], each = 3))
x <- 1:9
y <- rnorm(9) + rep(c(1,-1,1), each=3)
# define a palette (the colors should be in the same order as your group factor levels)
mypalette <- c("grey20", "firebrick", "royalblue")
plot(x,y, col = mypalette[as.numeric(group)], pch=16, cex=3)
yields
You'll notice I didn't use scatterplot3d, because your question is actually unrelated to that function !
If you want pre-built color palettes, you can have a look at the viridis package or the RcolorBrewer package.
RoB
- 1,833
- 11
- 23
