在地图中覆盖图例覆盖图
Overlaying Legend in Map Plot Covers Plot
我正在尝试使用 map
库创建绘图。然而,图例似乎总是覆盖地图,而我希望它偏向一边以便情节可见。以下是生成相关地图的代码:
library(maps)
library(maptools)
map(database = "county", region = "Michigan")
legend("center", c("Legend 1","Legend 2"), horiz = FALSE)
这是生成的图像(图例掩盖了情节)。
关于如何移动图例有什么想法吗?谢谢!
可以为图例使用 x 和 y 参数。在这种情况下,可以指定要放置图例的位置的纬度和经度或使用默认位置:
"bottomright"、"bottom"、"bottomleft"、"left"、"topleft"、"top"、"topright"、"right" 和 "center"
示例:
legend( c("Legend 1","Legend 2"), x="bottomleft")
或指定 x 和 y 坐标(带有纬度和经度)。对于密歇根州:
legend( c("Legend 1","Legend 2"), x=-90, y=43)
如果图例仍然不在正确的位置,请考虑手动设置图表的绘图限制:
map(database = "county", region = "Michigan", xlim=c(-91, -82))
我正在尝试使用 map
库创建绘图。然而,图例似乎总是覆盖地图,而我希望它偏向一边以便情节可见。以下是生成相关地图的代码:
library(maps)
library(maptools)
map(database = "county", region = "Michigan")
legend("center", c("Legend 1","Legend 2"), horiz = FALSE)
这是生成的图像(图例掩盖了情节)。
关于如何移动图例有什么想法吗?谢谢!
可以为图例使用 x 和 y 参数。在这种情况下,可以指定要放置图例的位置的纬度和经度或使用默认位置:
"bottomright"、"bottom"、"bottomleft"、"left"、"topleft"、"top"、"topright"、"right" 和 "center"
示例:
legend( c("Legend 1","Legend 2"), x="bottomleft")
或指定 x 和 y 坐标(带有纬度和经度)。对于密歇根州:
legend( c("Legend 1","Legend 2"), x=-90, y=43)
如果图例仍然不在正确的位置,请考虑手动设置图表的绘图限制:
map(database = "county", region = "Michigan", xlim=c(-91, -82))