我正在使用awesomeIcons()函数,其中找到了一个医院图标('hospital-o')。然而,该图标事实上是黑色的。使用下面的代码,我无法将其颜色更改为白色。
library(dplyr)
library(DT)
library(flexdashboard)
library(leaflet)
library(leaflet.extras)
library(reshape2)
library(shiny)
icons <- awesomeIcons(
icon = 'hospital-o',
lib = 'fa',
markerColor = getColor(DATASET))
getColor()函数的代码如下:
getColor <-
function(DATASET) {
sapply(DATASET$VAR, function(VAR) {
if(VAR == 0 | is.na(VAR) | is.nan(VAR)) {"gray"}
else if(VAR <= 2){"darkgreen"}
else if(VAR <= 4){"green"}
else if(VAR <= 6){"orange"}
else if(VAR <= 10){"red"}
else {"darkred"}
})
}
颜色函数正在工作(即灰色、绿色、红色和标记)。我尝试了类似于这样的方法(还实现了颜色代码),但没有结果:
icons <- awesomeIcons(
icon = 'hospital-o',
lib = 'fa',
iconColor = "white",
markerColor = getColor(DATASET))
虚拟数据
NAME VAR latitude longitude
A 1 51.792 4.682
B 12 52.214 6.894
C 6 51.982 5.148
制作地图:
map <- leaflet(DATASET) %>%
addTiles() %>%
addAwesomeMarkers(lng = ~longitude, lat = ~latitude, icon = icons, label = ~as.character(DATASET$NAME),
popup = paste0("<strong>Name: </strong>", DATASET$NAME, "<br>","<strong>VAR: </strong>", DATASET$VAR)) %>%
addMarkers(lng = longitude, lat = latitude) %>%
addProviderTiles(providers$nlmaps.pastel, group = "Pastel") %>%
addMiniMap(toggleDisplay = T, minimized = T, position = "bottomright") %>%
addLayersControl(
baseGroups = c("Pastel"),
options = layersControlOptions(collapsed = F), position = "topleft") %>%
addMarkers(lng = longitude, lat = latitude)
能有人帮助我吗?先在这里谢谢!
iconColor = "#FFFFFF"
。 - MLavoie