在3D散点图R上标记特定点

时间:2018-09-17 18:21:24

标签: r 3d scatter-plot

我正在使用R封装图形在R中绘制3d散点图。我想用不同的颜色标记该图上的特定点,就像在2d图上使用plot()和lines()一样。

如何在3d散点图上做到这一点?

#Set plot points
x = seq(-10, 10, length= 100)
y = x
fr = function(x, y) { r = sqrt(x^2+y^2); 10 * sin(r)/r }
z = outer(x, y, fr)
z[is.na(z)] = 1
#Plot using scatterplot 3d
X = expand.grid(x,y)
x = X[,1]
y = X[,2]
z = c(z)
scatterplot3d(x,y,z,color="lightblue",pch=21,main="3-D Scatter Plot")
#Get maximum for this function
fn = function(x) { r = sqrt(x[1]^2+x[2]^2); 10 * sin(r)/r }
optim(c(-1.2,1,4), fn, method = "Nelder-Mead")
#Mark maximum on the graph in different color
#How to??

感谢您的帮助

0 个答案:

没有答案
相关问题