R ggplotly()和颜色注释-您是如何做到的?

R ggplotly()和颜色注释-您是如何做到的?,r,ggplot2,r-plotly,ggplotly,annotate,R,Ggplot2,R Plotly,Ggplotly,Annotate,我试图从带有悬停点的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",

我试图从带有悬停点的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 
库(“ggplot2”)
图书馆(“阴谋地”)

测试数据不是
ggplotly
解决方案,而是
plotly
解决方案。(;至少在我看来,
ggplotly
如果你想制作一个快速交互式版本的ggplot,那就很好了。但是,
ggplotly
仍然有很多问题,无法转换每个ggplot。尝试以下方法:

库(“ggplot2”)
图书馆(“阴谋地”)
测试数据