无法使用Terra r Pakage为点Shapefile添加传奇
我想添加绘制在栅格顶部的点shapefile的传奇。我正在使用以下代码
library(terra)
f <- system.file("ex/elev.tif", package="terra")
r <- rast(f)
plot(r)
d <- data.frame(lon=c(6.0,6.1,6.2,6.2),
lat = c(49.7,49.8,49.9,49.6),
Class=c("Yes", "No"))
m <- vect(d, geom=c("lon", "lat"), crs="+proj=longlat +datum=WGS84")
plot(m, add = T, col = c("red", "blue"), legend=TRUE,
plg=list(legend=c("No", "Yes")))
您可以从传说所缺少的输出中看到。如果我添加了传奇功能,
legend("bottomright", legend=names(table(points$Class)), col=c("red", "blue"))
我如何在传奇中拥有各自的颜色?
I want to add legend for point shapefile plotted on top of a raster. I am using the following code
library(terra)
f <- system.file("ex/elev.tif", package="terra")
r <- rast(f)
plot(r)
d <- data.frame(lon=c(6.0,6.1,6.2,6.2),
lat = c(49.7,49.8,49.9,49.6),
Class=c("Yes", "No"))
m <- vect(d, geom=c("lon", "lat"), crs="+proj=longlat +datum=WGS84")
plot(m, add = T, col = c("red", "blue"), legend=TRUE,
plg=list(legend=c("No", "Yes")))
As you can see from the output that the legend is missing. If I add a legend function like
legend("bottomright", legend=names(table(points$Class)), col=c("red", "blue"))
It adds a legend withou the colours.
How can I have the respective colours in the legend?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要告诉
绘图
函数要使用哪个图层:You need to tell the
plot
function which layer to use: