繁体   English   中英

R:在填充轮廓图上绘制散点图

[英]R: Plotting a scatterplot over a filled.contour plot

我对R很陌生,并使用内插数据(例如在不规则网格上绘制轮廓线中的数据)制作了fill.contour图。 使用来自在不规则网格上绘制轮廓的一些样本数据,我使用以下代码制作了fill.contour和简单散点图

x <- datr$Lat
y <- datr$Lon
z <- datr$Rain

require(akima)
fld <- interp(x,y,z)
filled.contour(fld)
plot(x,y)

有没有办法在同一块图上(重叠)制作plot(x,y)和filled.contour(fld)? 我已经尝试过点(x,y),但这与x和y轴不匹配。 在Matlab中,我相信可以保留,但是我不确定如何在R上进行。

谢谢!

您可以plot.title使用plot.titleplot.axes参数:

x <- 10*1:nrow(volcano)
y <- 10*1:ncol(volcano)
filled.contour(x, y, volcano, plot.title = { 
  points(x = 200, y = 200)
})

通过

一种方法是读取fill.contour的代码,然后像这样进行一些黑客攻击:

使你的身材:

filled.contour(fld)

通过从参数列表复制它们来定义这些常量。

nlevels = 20
zlim = range(z, finite = TRUE)
las = 1 
levels = pretty(zlim, nlevels)
xlim = range(x, finite = TRUE)
ylim = range(y, finite = TRUE)
xaxs = "i"
yaxs = "i"
asp = NA

通过复制功能体中的代码来计算这些值

mar.orig <- (par.orig <- par(c("mar", "las", "mfrow")))$mar
w <- (3 + mar.orig[2L]) * par("csi") * 2.54

通过复制功能主体中的代码来设置布局

layout(matrix(c(2, 1), ncol = 2L), widths = c(1, lcm(w)))

请注意,该图实际上是在色标之后绘制的,但是我们不愿屈服于布局的顺序,因为layout实际上将“当前”区域设置为最后一个区域,因为第一次调用plot.new会导致当前环绕到第一个区域的区域。 因此,当您设置绘图窗口并通过以下方式绘制点时:

plot.window(ylim=ylim,xlim=xlim)
points(x,y)
title(main='title',
      sub='Sub-Title',
      xlab='This is the x axis',
      ylab='This is the y axis')

它们根据需要覆盖图形。

暂无
暂无

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

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