Plotting curves given by equations in R

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)

enter image description here


You can use contour to plot the two branches of your hyperbola.

f <- function(x,y) x^2 - 3*y^2 + 2*x*y - 20
x <- y <- seq(-10,10,length=100)
z <- outer(x,y,f)
contour(
  x=x, y=x, z=z, 
  levels=0, las=1, drawlabels=FALSE, lwd=3
)

enter image description here

Tags:

Graphics

R