In R, is there a way to plot 2D curves given by equations? For example, how can I plot the hyperbola given by equation x^2 - 3*y^2 + 2*x*y - 20 = 0?
To draw multiple curves in one plot, different functions are created separately and the curve() function is called repeatedly for each curve function. The call for every other curve() function except for the first one should have added an attribute set to TRUE so that multiple curves can be added to the same plot.
curve() function in R Language is used to draw a curve for the equation specified in the argument.
The plot() function in R isn't a single defined function but a placeholder for a family of related functions. The exact function being called will depend upon the parameters used. At its simplest, plot() function simply plots two vectors against each other. This gives a simple plot for y = x^2.
Just for the record - a ggplot version
library(ggplot2)
library(dplyr)
f <- function(x,y) x^2 - 3*y^2 + 2*x*y - 20
seq(-10,+10,length=100) %>%
expand.grid(x=.,y=.) %>%
mutate(z=f(x,y)) %>%
ggplot +
aes(x=x,y=y,z=z) +
stat_contour(breaks=0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With