I used stat_function in ggplot2 in order to plot a straight line. So within the range of -20 to 20, it plots y = x * 1.
ggplot(data.frame(x = c(-20, 20)), aes(x)) +
stat_function(fun = function(x) { x**1 },
geom = "line", color = '#1e466e')
I'd like to figure out a way to create a plane and not just a line. I tried building out the process using the ggplot workflow by adding a variable and making stat_function report a z in relation to x and y. But this just gives me a blank plot.
ggplot(data.frame(x = c(-20, 20), y = c(-20, 20)), aes(x, y)) +
stat_function(fun = function(z) { x**1 + y },
geom = "line", color = '#1e466e')
I'm seeing that this is a lot cause without a ggplot2 extension. But when I find examples using plotly or something else, I only see examples where the x and y and z are reported as columns of a dataframe and the plane is a regression plane through the points, such as in this stackoverflow example: But I don't want to plot points that exist in three coordinates but rather a plane that lives within two parallel lines that exist in three coordinates.
Is there a way to create planes to represent different linear equations, for example these equations?
x + 2y + z = 2
3x + 8y + z = 12
4y + z = 12
These planes should intersect at this point: (x = 2, y = 1, z = -2)
The inspiration for my small project was watching Gilbert Strang's linear algebra video at this link and wondering if it's possible to re-create in R.