【发布时间】:2020-04-03 10:42:05
【问题描述】:
我正在尝试使用带有悬停点的 Plotly 的附加功能从 ggplot 复制绘图,但它会剥离注释并尝试一切以实现相同的视图但没有成功。
library("ggplot2")
library("plotly")
test_data <- data.frame(A = c(1,5,7,4,2),
B = c(3,3,6,8,4))
my_days <- as.Date(c("2010-01-01", "2010-02-01",
"2010-03-01", "2010- 4-01",
"2010-05-01"))
df <- data.frame(test_data, my_days)
# Anotate Box
s_1 <- unique(min(df$my_days))
s_2 <- unique(max(df$my_days))
target <- 1
plot_out <- df %>%
group_by(my_days) %>%
summarise(prop = sum(A / B)) %>%
ggplot(aes(x =my_days, y = prop)) +
geom_line(color = "purple") +
annotate("rect", xmin = s_1, xmax = s_2, ymin = -Inf, ymax = target, alpha = .2, fill = "red") +
annotate("rect", xmin = s_1, xmax = s_2, ymin = target, ymax = Inf, alpha = .2, fill = "green")
plot_out # Plot with Colour
ggplotly(plot_out) # This gives the hover info points , but removes the annotates
【问题讨论】:
标签: r ggplot2 r-plotly ggplotly annotate