【发布时间】:2021-09-12 02:14:56
【问题描述】:
在下面的图表中,我想在图例中为蓝色参考线添加一个项目,在本示例中,我们可以将其称为“任意线”。任何人都可以为我提供一个解决方案来将其纳入传说吗?请注意,最终的情节必须以情节形式呈现。
library(tidyverse)
library(plotly)
dat <- data.frame(peeps= c("Bill", "Bob", "Becky"),
vals = c(10, 15, 12),
label = c("8% Fake", "12% Pizza", "45% Becky"),
grp = c("Bears", "Bears", "Mongoose") %>% as.factor)
p1 <- dat %>%
ggplot(aes(x = peeps, y = vals, fill = grp)) +
geom_bar(stat = "identity") +
geom_segment(aes(x = 0.55, xend = 3.45, y = 5, yend = 5), color = "blue") +
scale_y_continuous(expand = c(0, 0)) +
coord_flip()
ggplotly(p1) %>%
layout(legend = list(orientation = "h",
xanchor = "center",
y = -0.15,
x = 0.5))
【问题讨论】: