本文介绍了更改 R 中 3dplots 中轴标题和标签的方向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

df 

我正在使用 scatterplot3d 包绘制 3D 图.

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

现在我想做 2 个修改.一个是使这些轴的垂直标题水平,接下来是为 x 的值放置一个标签,例如在 x 值中为 1 放置一个标签第一个间隔",依此类推.我怎么做?

另外,我怎样才能使点线性或平面而不是点.

解决方案

为此,您需要隐藏当前标签,并使用 text() 函数在正确位置添加旋转标签;如此处所述 旋转 y 轴标签在 scatterplot3d(调整到轴的角度)

set.seed(42)scatterplot3d(rnorm(20), rnorm(20), rnorm(20), ylab = "")文本(x = 5,y = -2.5,Y 轴",srt = 45)

并且例如在 x 值中为 1 放置一个标签第一个间隔",依此类推.我该怎么做?

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

xlabs <- c("第一个间隔", "第二个", "第三个", "第四个", "这是 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=" ")#或者scatterplot3d(x,y,z, type="h", lwd=5, pch="")

I have a question that might be easy for a person who is expert in R plot. I need to draw 3D plot in R. My data is as follows:

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)

I am drawing a 3D Plot using scatterplot3d package.

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")

Now I want to do 2 modifications. One is to make the vertical title of those axis horizontal and the next is to put a label for values of x and for example put a label "first interval" for 1 in x values and so one and so forth. How an I do it?

Also, how can I make the points linear or plane instead of dots.

解决方案

To do this you need to hide the current label, and use the text() function to add a rotated label in the correct spot; as described here 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)

From the documentation - https://cran.r-project.org/web/packages/scatterplot3d/scatterplot3d.pdfUse the x.ticklabs attribute, for example:

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 offers "lines" and "vertical lines", for example:

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

这篇关于更改 R 中 3dplots 中轴标题和标签的方向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 04:28