简体   繁体   English

R:如何绘制不等式图(3个变量)

[英]R: How to plot a graph of an inequality function (3 variables)

My inequality: 我的不平等:

x^2 + y^2 + z^2 < 1 AND x^2 + y^2 < z^2

How to plot this logical combination of inequalities in R? 如何绘制R中不等式的这种逻辑组合? (range for all three axis = -1,1) (所有三个轴的范围= -1,1)

Here's a rgl solution, to make a 3D-plot and adding points colored by your condition. 这是一个rgl解决方案,可以制作3D图并添加根据您的情况着色的点。

# some data on a grid
x = seq(-1, 1, len = 10); 
df <- expand.grid(x=x,y=x,z=x)
# indicator for color
df$ind <- with(df, x^2 + y^2 + z^2 < 1 & x^2 + y^2 < z^2)

require(rgl)
# empty plot
plot3d(df$x, df$y, df$z, type = 'n')
# add points
with(df[df$ind, ], points3d(x, y, z, color = 'red', size = 10))
with(df[!df$ind, ], points3d(x, y, z, color = 'blue', size = 10))

Using rgl : 使用rgl

x <- y <- z <- seq(-1, 1, by=0.01)
df <- setNames(expand.grid(x, y, z), c("x", "y", "z"))
df <- transform( df, ueq = (x^2 + y^2 + z^2 < 1) & (x^2 + y^2 < z^2))
df$color <- ifelse(df$ueq == TRUE, "green" , "red")
require(rgl)
with(df[df$ueq == TRUE, ], plot3d(x=x, y=y, z=z, col=color, type="p", size=5))
grid3d(c("x", "y+", "z"))

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM