简体   繁体   English

将abline添加到填充的等高线图中

[英]Add abline to filled contour plot

I drew a contour plot and added a diagonal line: 我绘制了一个等高线图并添加了一条对角线:

library(MASS)
library(fields)
x <- c(21.06, 28.89, 23.00, 23.61, 23.61, 22.83, 30.44)
y <- c(26.56, 24.00, 13.06, 18.61, 18.61, 14.17, 25.33)
z <- kde2d(x, y, n=32, lims = c(0,32,0,32))
contour(z, col = "red", main = "Density estimation: contour plot",
       las=0,

    plot.title=
               {
      title(xlab=expression(alpha),cex.lab=2)
      mtext(expression(beta),2,cex=2,line=3,las=1)
               } 
)
abline(0, 1, col = "red", lwd = 2) 

第一张图

I think I like the filled contour more, but now the line is off: 我想我更喜欢填充的轮廓,但现在线条已关闭:

filled.contour(z,  plot.title={
   title(main = "Density estimation: contour plot")
   title(xlab=expression(alpha),cex.lab=2)
   mtext(expression(beta),2,cex=2,line=3,las=1)
 })
 abline(0, 1, col = "red", lwd = 2) 

第二张图

You could throw the abline in there: 你可以在那里抛出abline

library(MASS)

x <- c(21.06, 28.89, 23.00, 23.61, 23.61, 22.83, 30.44)
y <- c(26.56, 24.00, 13.06, 18.61, 18.61, 14.17, 25.33)
z <- kde2d(x, y, n = 32, lims = c(0, 32, 0, 32))

filled.contour(z,  plot.title={
  title(main = "Density estimation: contour plot")
  title(xlab=expression(alpha),cex.lab=2)
  mtext(expression(beta),2,cex=2,line=3,las=1)
  abline(0, 1, col = "red", lwd = 2)
})

在此输入图像描述

Or (as was suggested in a comment), you might be better off doing something like: 或者(正如评论中所建议的那样),你最好做一些事情:

filled.contour(
  z,
  plot.title = {
    title(main = "Density estimation: contour plot")
    title(xlab = expression(alpha), cex.lab = 2)
    mtext(expression(beta), 2, cex = 2, line = 3, las = 1)
  },
  plot.axes = {
    abline(0, 1, col = "red", lwd = 2)
  }
)

Simply because it feels a little weird putting an abline in plot.title . 只是因为在plot.title放置一个abline感觉plot.title

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM