【问题标题】:How to create a plot function when the title differ?标题不同时如何创建绘图功能?
【发布时间】:2021-04-12 09:25:01
【问题描述】:

我想创建一张法国地图,并在不同的地图上显示不同的点。

代码很容易做:

library(raster)

#mydata
pointA <- data.frame(longitude = c(5.819472,5.384418 ),
                   latitude = c(46.11558, 46.18197))
pointC <- data.frame (longitude = 4.218322,
                     latitude = 44.20379)


cartes <- function(point){
 france <- getData('GADM', country = 'FRA', level = 1) # Map of France
 plot(france, border = "red", main = "Name of the point") 
 points(point$longitude, point$latitude)
}

cartes(pointA)
cartes(pointC)

但我找不到根据点名称更改标题的方法...

你知道怎么做吗?

【问题讨论】:

    标签: r function title


    【解决方案1】:

    使用ensym() 可能会对您有所帮助:

    library(raster)
    
    #mydata
    pointA <- data.frame(longitude = c(5.819472,5.384418 ),
                         latitude = c(46.11558, 46.18197))
    pointC <- data.frame (longitude = 4.218322,
                          latitude = 44.20379)
    
    
    cartes <- function(point){
      france <- getData('GADM', country = 'FRA', level = 1) # Map of France
      plot(france, border = "red", main = ensym(point)) 
      points(point$longitude, point$latitude)
    }
    
    cartes(pointA)
    cartes(pointC)
    

    【讨论】:

      猜你喜欢
      • 2021-07-13
      • 1970-01-01
      • 2021-04-02
      • 2023-03-19
      • 2011-08-06
      • 1970-01-01
      • 1970-01-01
      • 2014-07-29
      • 1970-01-01
      相关资源
      最近更新 更多