[英]How to plot several graphs one after another
I would like to plot my graphs in one 3d coordinate system. 我想在一个3D坐标系中绘制图形。 I it possible to plot these graphs in series (one after another) without defining az coordinate. 我可以在不定义z坐标的情况下连续(一幅一幅)绘制这些图。
x = 460:650
y1 = rnorm(191, 5, 2)
y2 = rnorm(191, 4, 1)
y3 = rnorm(191, 2, 0.8)
plot(x, y1, col = "red", type = "l")
lines(x, y2, col = "green", add = T)
lines(x, y3, col = "blue", add = T)
Here is an example data set. 这是一个示例数据集。 At the moment I plot my graphs all in the same 2d coordinate system. 此刻,我将所有图形绘制在相同的2d坐标系中。 I want them in the same 3d coordinate system. 我希望它们在相同的3d坐标系中。 Meaning the red curve should be the foremost and the blue curve the last curve. 意味着红色曲线应位于最前,蓝色曲线应位于最后。 All these 3 plots can have the same distance from each other. 所有这三个图可以具有相同的距离。
This is all types of ugly but, I think it does what you want. 这是所有类型的丑陋,但是,我认为它可以满足您的需求。 Adapted from https://plot.ly/r/3d-line-plots/ . 改编自https://plot.ly/r/3d-line-plots/ 。
library(plotly)
x = rep(460:650,3)
y1 = rnorm(191, 5, 2)
y2 = rnorm(191, 4, 1)
y3 = rnorm(191, 3, 1)
z = c(rep(1,191),rep(2,191),rep(3,191))
z <- ordered(z, levels=c('1', '2', '3'))
y_all<-(c(y1,y2,y3))
plot_ly(x = ~x, y = ~y_all, z = ~z, type = 'scatter3d', mode = 'lines', color = ~z)
As others mentioned, no you cannot plot in z-space without defining some z. 就像其他人提到的,没有定义z不能在z空间中绘图。 Here, you just need a categorical z to set things against and then you can tell plot_ly()
to format it "nicely" 在这里,您只需要一个分类z来设置内容,然后您就可以告诉plot_ly()
进行格式化。
Thank you for your help. 谢谢您的帮助。 I have decided to define z as well. 我决定也定义z。 You are right. 你是对的。 Otherwise it is a bit inelegant. 否则,它有点不雅观。
data = data.frame(x = c(460, 465, 470, 475, 480, 485, 490, 495, 500, 505, 510, 515, 520, 525, 530, 535, 540, 545, 550,
460, 465, 470, 475, 480, 485, 490, 495, 500, 505, 510, 515, 520, 525, 530, 535, 540, 545, 550,
460, 465, 470, 475, 480, 485, 490, 495, 500, 505, 510, 515, 520, 525, 530, 535, 540, 545, 550),
time = c(rep(0, 19), rep(0.1, 19), rep(0.2, 19)), values = c(80,104,138,188,212,247,287,324,359,366,393,417,397,371,364,345,321,319,295,
80,104,138,188,212,247,287,324,359,366,393,417,397,371,364,345,321,319,295,
80,104,138,188,212,247,287,324,359,366,393,417,397,371,364,345,321,319,295))
lines3D(data$x, data$time, data$values)
When I use the lines3D function how can I label and define the axes? 使用lines3D函数时,如何标注和定义轴? At the moment the axes are only labelled with x, y and z. 目前,这些轴仅标有x,y和z。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.