我想将图像嵌入到 plotly 图表的 x 轴中(而不是代替 x 轴)。我尝试过的代码:
library(plotly)
library(dplyr)
library(tidyr)
Animals <- c("giraffes", "orangutans", "monkeys")
SF_Zoo <- c(20, 14, 23)
LA_Zoo <- c(12, 18, 29)
data <- data.frame(Animals, SF_Zoo, LA_Zoo) %>%
pivot_longer(cols = c(SF_Zoo, LA_Zoo)) %>%
mutate(Animals = paste(Animals, "<img src='https://images.plot.ly/language-icons/api-home/r-logo.png'</img>"))
plot_ly(data, x = ~Animals, y = ~value, type = 'bar', color = ~name) %>%
layout(
barmode = "stack"
)
可以看出,img
标签被打印为文字字符串。我尝试过包装刻度标签Animals
,htmltools::HTML
但没有成功。
本plotly 指南讨论了在绘图区域内嵌入图像/徽标,但我想将图像嵌入为刻度标签的一部分。此python SO 解决方案将刻度标签完全替换为图像。