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.
One is to make the vertical title of those axis horizontal
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)
and for example put a label "first interval" for 1 in x values and so one and so forth. How an I do it?
From the documentation - https://cran.r-project.org/web/packages/scatterplot3d/scatterplot3d.pdf Use 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)
Also, how can I make the points linear or plane instead of dots.
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=" ")
来源:https://stackoverflow.com/questions/52030865/change-direction-of-axis-title-and-label-in-3dplots-in-r