使用 visNetwork 更改 fontAwesome 图标的颜色
Changing color of fontAwesome icons with visNetwork
我尝试了 visNetwork R 包 documentation 中提出的关于使用 fontAwesome 图标的示例。
在下面的示例中,我使用了通过 data.frame 传递节点属性的选项。但是,输出中图标的颜色默认为蓝色。
library(visNetwork)
nodes <- data.frame(id = 1:3,
shape = "icon",
icon.face = "FontAwesome",
color = c("#800000", "#0000ff", "#ffa500"), # doesn't have any effect on icon color
icon.code = c("f1ad", "f015", "f007"))
edges <- data.frame(from = c(1,2), to = c(2,3))
visNetwork(nodes, edges) %>%
addFontAwesome()
似乎替代方法是使用文档中描述的分组选项。但是,我希望 data.frame 选项也能正常工作,但我现在无法弄清楚我在上面做错了什么。
nodes <- data.frame(id = 1:3,
shape = "icon",
group = c("A", "B", "C"))
edges <- data.frame(from = c(1,2), to = c(2,3))
visNetwork(nodes, edges) %>%
visGroups(groupname = "A", shape = "icon",
icon = list(code = "f1ad", color = "#800000")) %>%
visGroups(groupname = "B", shape = "icon",
icon = list(code = "f015", color = "#0000ff")) %>%
visGroups(groupname = "C", shape = "icon",
icon = list(code = "f007", color = "#ffa500")) %>%
addFontAwesome()
将 color
更改为 icon.color
一切正常:
library(visNetwork)
nodes <- data.frame(id = 1:3,
shape = "icon",
icon.face = "FontAwesome",
icon.color = c("#800000", "#0000ff", "#ffa500"), # doesn't have any effect on icon color
icon.code = c("f1ad", "f015", "f007"))
edges <- data.frame(from = c(1,2), to = c(2,3))
visNetwork(nodes, edges) %>%
addFontAwesome()
我尝试了 visNetwork R 包 documentation 中提出的关于使用 fontAwesome 图标的示例。
在下面的示例中,我使用了通过 data.frame 传递节点属性的选项。但是,输出中图标的颜色默认为蓝色。
library(visNetwork)
nodes <- data.frame(id = 1:3,
shape = "icon",
icon.face = "FontAwesome",
color = c("#800000", "#0000ff", "#ffa500"), # doesn't have any effect on icon color
icon.code = c("f1ad", "f015", "f007"))
edges <- data.frame(from = c(1,2), to = c(2,3))
visNetwork(nodes, edges) %>%
addFontAwesome()
似乎替代方法是使用文档中描述的分组选项。但是,我希望 data.frame 选项也能正常工作,但我现在无法弄清楚我在上面做错了什么。
nodes <- data.frame(id = 1:3,
shape = "icon",
group = c("A", "B", "C"))
edges <- data.frame(from = c(1,2), to = c(2,3))
visNetwork(nodes, edges) %>%
visGroups(groupname = "A", shape = "icon",
icon = list(code = "f1ad", color = "#800000")) %>%
visGroups(groupname = "B", shape = "icon",
icon = list(code = "f015", color = "#0000ff")) %>%
visGroups(groupname = "C", shape = "icon",
icon = list(code = "f007", color = "#ffa500")) %>%
addFontAwesome()
将 color
更改为 icon.color
一切正常:
library(visNetwork)
nodes <- data.frame(id = 1:3,
shape = "icon",
icon.face = "FontAwesome",
icon.color = c("#800000", "#0000ff", "#ffa500"), # doesn't have any effect on icon color
icon.code = c("f1ad", "f015", "f007"))
edges <- data.frame(from = c(1,2), to = c(2,3))
visNetwork(nodes, edges) %>%
addFontAwesome()