简体   繁体   English

R,scatterplot3d:为分组分配特定颜色并更改字体

[英]R, scatterplot3d: Assigning specific color to group and change font

I am relatively new to R. I am trying to plot a 3D scatterplot.我对 R 比较陌生。我正在尝试绘制 3D 散点图。 I have 4 continuous variables, one of which defines the group.我有 4 个连续变量,其中一个定义了组。 There are 6 groups.有6组。 I tried this code: scatterplot3d(x,y,z,color=as.numeric(group),pch=20) The colors are all too similar.我试过这个代码: scatterplot3d(x,y,z,color=as.numeric(group),pch=20)颜色都太相似了。 How can I assign specific colors to the 6 groups?如何为 6 个组分配特定颜色? Could you also tell me how to change the font to Calibri?你能告诉我如何将字体更改为 Calibri 吗? Thank you so much!非常感谢! :) :)

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.对于颜色部分,您必须设置一个调色板,然后使用您的数字group变量来访问调色板中的不同颜色。

eg例如

# 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 !您会注意到我没有使用 scatterplot3d,因为您的问题实际上与该功能无关!

If you want pre-built color palettes, you can have a look at the viridis package or the RcolorBrewer package .如果您想要预先构建的调色板,您可以查看viridisRcolorBrewer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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