如何向使用点阵制作的水平图添加线条(abline 不知何故不起作用)?

发布于 2024-12-07 07:40:08 字数 692 浏览 0 评论 0原文

我想在水平图上绘制水平线和垂直线,对应于从 74 到 76 的 x 值和从 28 到 32 的 y 值。下面是我的 R 代码。但是当我运行以下命令时,我得到了水平图,但没有线条。我也没有收到来自 R 的错误。我安装的默认主题是将值映射到粉色和青色的主题。我也尝试过使用面板功能,但也没有成功。

levelplot(d_fire_count_nom ~ longitude + latitude | factor(day)+factor(year), 
          data = asia,
          subset = (month == 10),  aspect="iso", contour = FALSE, layout=c(1,1), 
          main="If a fire occured in a region (low confidence) in October during 2001-2008", 
          scales=list(x=list(at=seq(from=60,to=98, by=1)), 
                      y=list(at=seq(from=5,to=38,by=1)),cex=.7, alternating=3), 
          xlim=c(60, 98), ylim=c(5, 38),
          abline=list(h=74:76, v=28:32, col="grey"))

I want to draw horizontal and vertical lines on my level plot corresponding to x values from 74 to 76 and y values from 28 to 32. Below is my R code. But when I run the following,I get the levelplots but no lines. I also recieve no error from R. The default theme on my installation is something which maps the values to pink and cyan. I have also tried using the panel function but no luck with that as well.

levelplot(d_fire_count_nom ~ longitude + latitude | factor(day)+factor(year), 
          data = asia,
          subset = (month == 10),  aspect="iso", contour = FALSE, layout=c(1,1), 
          main="If a fire occured in a region (low confidence) in October during 2001-2008", 
          scales=list(x=list(at=seq(from=60,to=98, by=1)), 
                      y=list(at=seq(from=5,to=38,by=1)),cex=.7, alternating=3), 
          xlim=c(60, 98), ylim=c(5, 38),
          abline=list(h=74:76, v=28:32, col="grey"))

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

維他命╮ 2024-12-14 07:40:08

这不是点阵图形的工作原理。事实上,如果您阅读 ?levelplot 您会发现名为 abline 的函数没有参数,所以我不确定您从哪里获得该语法。

您可以通过更改panel 函数向lattice 图形添加内容。有许多 panel.* 函数用于执行各种操作,例如绘制点、线、散点图平滑器等。在本例中,我们需要一个 panel.abline使用。所以我们定义了自己的panel函数。

这使用了 ?levelplot 中的第一个示例:

x <- seq(pi/4, 5 * pi, length.out = 100)
y <- seq(pi/4, 5 * pi, length.out = 100)
r <- as.vector(sqrt(outer(x^2, y^2, "+")))
grid <- expand.grid(x=x, y=y)
grid$z <- cos(r^2) * exp(-r/(pi^3))
levelplot(z~x*y, grid,
        panel = function(...){
            panel.levelplot(...)
            panel.abline(h = 2.5)
            panel.abline(v = 2.5)
        }, 
        cuts = 50, scales=list(log="e"), xlab="",
        ylab="", main="Weird Function", sub="with log scales",
        colorkey = FALSE, region = TRUE)

我们的新面板函数需要首先绘制 levelplot,因此我们首先调用 panel.levelplot。然后我们想要添加一些行,因此我们为此添加 panel.abline

That's not how lattice graphics work. In fact, if you read ?levelplot you'll see that there is no argument to that function called abline, so I'm not sure where you got that syntax from.

You add things to lattice graphics by altering the panel function. There are many panel.* functions for doing various things, like plotting points, lines, scatterplot smoothers, etc. In this case there's a panel.abline that we'd like to use. So we define our own panel function.

This uses the very first example from ?levelplot:

x <- seq(pi/4, 5 * pi, length.out = 100)
y <- seq(pi/4, 5 * pi, length.out = 100)
r <- as.vector(sqrt(outer(x^2, y^2, "+")))
grid <- expand.grid(x=x, y=y)
grid$z <- cos(r^2) * exp(-r/(pi^3))
levelplot(z~x*y, grid,
        panel = function(...){
            panel.levelplot(...)
            panel.abline(h = 2.5)
            panel.abline(v = 2.5)
        }, 
        cuts = 50, scales=list(log="e"), xlab="",
        ylab="", main="Weird Function", sub="with log scales",
        colorkey = FALSE, region = TRUE)

Our new panel function needs to first draw the levelplot, so we have it call panel.levelplot first. Then we want to add some lines, so we add panel.abline for that purpose.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文