I want to plot a function graph with R. The target function is z = 4*x^2 + lambda *y^2.
Given that z = c(0,2,4,6) and lambda = c(4, 2, 1, 0, -1, -2, -4).
I want to plot it in a contour map form.
The below is my code:
library(ggplot2)
rm(list=ls())
lambda = c(4, 2,1,0,-1,-2,-4)
plane = c(0,2,4,6)
x = seq(-5,5,length.out=100)
y = seq(-5,5,length.out=100)
i = 1
t = transform(expand.grid(x = x, y=y), z=4*x^2+lambda[i]*y^2)
dat = data.frame(t,"category"=c(rep(i,length(t$x))))
for(i in 2:7){
t = transform(expand.grid(x = x, y=y), z=4*x^2+lambda[i]*y^2)
dat = rbind(dat,
data.frame(t,"category"=c(rep(i,length(t$x)))))
}
ggplot(data = dat, aes(x = x, y=y, z=z, color = category))+
stat_contour(breaks = plane)
But I failed to plot the graph QQ...