我有一个轮廓图,我想绘制一个半径为1的单位圆,但是由于r自动包含y轴,所以我用来绘制单位圆的代码不适合y轴。 y轴上的圆的范围不是-1到1。
N <- 250
z.r <- seq(-2, 2, length = N)
z.i <- seq(-2, 2, length = N)
z.cr <- outer(z.r, rep(1,N))
z.ci <- outer(rep(1,N),z.i)
z <- complex(real=z.cr,imaginary=z.ci)
n1<-40
m2<-matrix(0,n1,n1)
diag(m2[-1,]) <-0.5 #fill the second diagonal
diag(m2[,-1]) <-0.5 #fill the other second diagonal
m2[1,n1]<-0.5
m2[n1,1]<-0.5
id <- diag(rep(1,n1))
# use lapply to define X
X1 <- lapply(1:length(z), function(k) solve(z[k]*id-m2))
# use the 2-norm at first
Y2 <- sapply(1:length(z), function(k) norm(X1[[k]], '2'))
a <- 5
# subset the Y's that are bigger than a
ind2 <- Y2 > a
install.packages("plotrix")
library(plotrix)
Y2_mat <- matrix(Y2, ncol = 250, nrow = 250)
contour(z.r, z.i, Y2_mat, nlevels = 150)
draw.circle(0, 0, radius = 1, lty = 2)
如何更改轴的比例,以便x轴和y轴使用相同的比例,或者有没有可能绘制适合两个轴的圆?