如何向使用点阵制作的水平图添加线条(abline 不知何故不起作用)?
我想在水平图上绘制水平线和垂直线,对应于从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不是
点阵
图形的工作原理。事实上,如果您阅读?levelplot
您会发现名为abline
的函数没有参数,所以我不确定您从哪里获得该语法。您可以通过更改
panel
函数向lattice
图形添加内容。有许多panel.*
函数用于执行各种操作,例如绘制点、线、散点图平滑器等。在本例中,我们需要一个panel.abline
使用。所以我们定义了自己的panel
函数。这使用了
?levelplot
中的第一个示例:我们的新面板函数需要首先绘制 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 calledabline
, so I'm not sure where you got that syntax from.You add things to
lattice
graphics by altering thepanel
function. There are manypanel.*
functions for doing various things, like plotting points, lines, scatterplot smoothers, etc. In this case there's apanel.abline
that we'd like to use. So we define our ownpanel
function.This uses the very first example from
?levelplot
: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 addpanel.abline
for that purpose.