【问题标题】:Add labels to a map plot向地图图添加标签
【发布时间】:2014-08-06 12:11:43
【问题描述】:

我正在尝试使用 R 在地图中添加标签。 我需要在标签上加上一个条件。尝试了多种选择,但无济于事。

png(filename="D:\\dm analysis3.png", width=959, height=593)
plot(zip,col=ifelse(zip@data$Seg=="Super Top",'Dark Green',
                      ifelse(zip@data$Seg=="Top Performer",'Light Green',
                    ifelse(zip@data$Seg=="Average Performer",'Yellow',
                           ifelse(zip@data$Seg=="Poor Performer",'Red',
                                  ifelse(zip@data$Seg=="Zero returns",'Dark Red',
                                         'Grey'))))),
     border=ifelse(zip@data$Seg=="Super Top",'Dark Green',
                   ifelse(zip@data$Seg=="Top Performer",'Light Green',
                          ifelse(zip@data$Seg=="Average Performer",'Yellow',
                                 ifelse(zip@data$Seg=="Poor Performer",'Red',
                                        ifelse(zip@data$Seg=="Zero returns",'Dark Red',
                                               'Grey'))))),
     bty="n")

with(subset(zip@data,zip@data$flag=="Y"),
     text(zip@data,labels=as.character(zip@data$code)))

map('state', plot = TRUE, fill = FALSE,add=TRUE)
dev.off()

谁能告诉我如何打印标签,我不会这样做

【问题讨论】:

    标签: r plot shapefile


    【解决方案1】:

    您必须在调用plot 命令之前准备好颜色矢量。在plot 命令中,给col 选项的参数是预先评估的,没有“好的,现在我正在绘制第n 点,所以让我们现在根据zip"中的当前索引计算第n个颜色是什么。

    编辑:我可以看到我可能回答得太及时了,而且越位了。你的问题到底是什么?它是否与您为 col 选项提供的内容有关? border 选项?还是稍后给text 命令的东西?

    【讨论】:

    • 我需要一个文本标签,它在我正在使用的每个市场中标记一个特定的值....我设法使用具有地理坐标的虚拟数据集来做到这一点...任何更好的方法都是非常感谢
    猜你喜欢
    • 1970-01-01
    • 2014-06-22
    • 2019-01-22
    • 1970-01-01
    • 1970-01-01
    • 2011-07-10
    • 1970-01-01
    • 2019-05-22
    • 2020-06-15
    相关资源
    最近更新 更多