r - R中传单中的addMarkers?
问题描述
我正在尝试通过此链接在传单包上重现 Rstudio 示例的结果。它一直工作到第 5 节。当我尝试使用具有完全相同设置的 AddMarkers 命令时:
##### Location Names
Location <- c("Atlanta ","Los Angeles","Chicago","New York","Dallas","Baltimore","Phoenix","Charlotte","Houston","San Antonio", "Seattle" )
#### Latitude and Longitude values for each of the above location
Lat <- c(33.74401,33.82377,41.78798,40.767309,32.88153,39.148492,33.45444,35.2406,29.935842,29.44838,47.714965 )
Lon <- c(-84.56032,-118.2668,-87.7738,-73.978308,-96.64601,-76.796211,-112.32401,-81.04028,-95.398436,-98.39908,-122.127166 )
#### Some hypothetical number of orders shipped out of each location
Orders <- c(1992,2500,3600,2252,3650,3450,4145,3945,5050,4300,1987)
#### Let us create some hypothetical class flags for the cities
Type <- c(rep("Yoda",5),rep("Vader",6))
### Create data set from the above vectors
df <- data.frame(Location, Lat,Lon,Orders,Type)
mymap <- leaflet() %>% addTiles()
mymap <- mymap %>%
addTiles(
'http://otile{s}.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.jpeg',
attribution = 'Tiles Courtesy of <a href="http://www.mapquest.com/">MapQuest</a> — Map data © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
) %>% setView(-97, 40, zoom = 4)
mymap %>% addMarkers(data=df,df[1,"Lon"],df[1,"Lat"], icon = JS("L.icon({
iconUrl: 'http://icons.iconarchive.com/icons/artua/star-wars/128/Master-Joda-icon.png',
iconSize: [75, 75]
})"))
我收到以下错误:
Error: $ operator is invalid for atomic vectors
知道为什么会这样吗?
解决方案
将图标添加为 R 列表,而不是 Javascript 对象,如下所示:
mymap %>%
addMarkers(data = df, lng = ~Lon, lat = ~Lat,
icon = list(
iconUrl = 'http://icons.iconarchive.com/icons/artua/star-wars/128/Master-Joda-icon.png',
iconSize = c(75, 75)
))
推荐阅读
- c# - 如何同步在线解锁的宝石、硬币和关卡等游戏数据(统一平台)
- spring-batch - Spring Batch 中的 LoopDecider 步骤始终运行
- autodesk-forge - 在 Forge 查看器中测量 3D 模型中的区域
- google-bigquery - BigQuery:DML 操作如何影响存储类(主动与长期存储)
- javascript - 如何避免做同样事情的 if-else 语句?
- go - struct 中的 Golang 通道的行为不同,通过在创建结构时传递它和在创建后通过函数传递
- ionic-framework - Ionic advanced-http: 标头值必须是字符串
- c# - 会话变量因文件较大而丢失
- php - Woocommerce分页不呈现
- node.js - 在 cmd 提示符下运行“节点”会引发错误