更改R中3dplots中轴标题和标签的方向?

时间:2018-08-26 23:02:12

标签: r plot scatter-plot scatter3d

我有一个问题,对于R绘图领域的专家来说可能很容易。我需要在R中绘制3D图。我的数据如下:

df <- data.frame(a1 = c(489.4,  505.8,  525.8,  550.2,  576.6),
a2 = c(197.8,  301,    389.8,  502,    571.2),
b1 = c(546.8,  552.6,  558.4,  566.4,  575),
b2 = c(287.2,  305.8,  305.2,  334.4,  348.6), c1 = c(599.6,  611.4,  
623.6,  658,    657.4), c2 = c(318.8,  423.2,  510.8,  662.4,  656),
d1 = c(616,    606.8,  600.2,  595.6,  595),
  d2 = c(242.4,  292.8,  329.2,  378,    397.2),
e1 = c(582.4,  580,    579,    579,    579),
e2 = c(214,    255.4,  281.8,  303.8,  353.8))

colnames(df) <- rep(c("V1", "V2"), 5)
df.new <- rbind(df[, c(1, 2)],df[, c(3, 4)],df[, c(5, 6)],               
df[, c(7, 8)],df[, c(9, 10)])
df.new$Group <- factor(rep(c("a","b","c","d","e"), each = 5))
df.new$Class <- rep(c(1:5), 5)

我正在使用scatterplot3d软件包绘制3D图。

x=df.new$Class
y=V1
z=V2
scatterplot3d(x,y,z, pch = 16, color=colors,main="3D V1 v.s V2",xlab = 
"Class",ylab = "V1", zlab = "V2")

现在我想做2个修改。一种是使那些轴的垂直标题成为水平,另一种是为x值放置一个标签,例如在x值中为1放置一个标签“ first interval”,依此类推。我该怎么做?

此外,如何使点成为线性或平面而不是点。

1 个答案:

答案 0 :(得分:1)

  

一种是使这些轴的垂直标题为水平

为此,您需要隐藏当前标签,并使用text()函数在正确的位置添加旋转的标签;如此处Rotate y-axis label in scatterplot3d (adjust to angle of axis)

所述
set.seed(42)
scatterplot3d(rnorm(20), rnorm(20), rnorm(20), ylab = "")
text(x = 5, y = -2.5, "Y-axis", srt = 45)
  

,例如,在x值中将1标记为“第一个间隔”,依此类推。我该怎么做?

摘自文档-https://cran.r-project.org/web/packages/scatterplot3d/scatterplot3d.pdf 使用x.ticklabs属性,例如:

xlabs <- c("first interval", "second", "third", "fourth", "this is 5")
scatterplot3d(x,y,z, pch =16,main="3D V1 v.s V2",xlab = "Class",ylab = "V1", zlab = "V2", x.ticklabs=xlabs)
  

此外,如何使点成为线性或平面而不是点。

Scatterplot3d提供“线”和“垂直线”,例如:

scatterplot3d(x,y,z , type="l", lwd=5, pch=" ")
#or
scatterplot3d(x,y,z , type="h", lwd=5, pch=" ")