【发布时间】:2021-12-26 20:02:19
【问题描述】:
我有一个条形图,条形图根据因子变量着色。我需要在指定位置的每个条上放置一个目标标记。我可以毫无问题地将标记放置在图上,但在图例中,目标标记出现了 3 次,而我只希望它出现一次。我相信这种行为与条形的颜色有关,但这种颜色是必须保留的。谁能给我一个解决方案,让目标标记只出现在图例上一次?
library(tidyverse)
library(plotly)
data.frame(grp = c("x", "y", "z") %>% as.factor,
vals = c(10, 15, 20)) %>%
plot_ly(
x = ~vals,
y = ~grp,
color = ~grp,
colors = c("red", "green", "blue"),
type = "bar"
) %>%
add_markers(name = "target",
x = 17,
marker = list(
color = "black")
)
【问题讨论】: