ggplotly 删除 R 中的图例上标和标题

ggplotly removes legend superscript and caption in R

我正在尝试通过 ggplotly 创建带有 ggplot object 的交互式绘图。 ggplot 绘图很好,但 ggplotly 从图例中删除了 superscript,也删除了绘图的 caption

我该如何解决这个问题?

    library(tidyverse)
    library(plotly)
    
        # df
        Pollutant_1 = c(2.5, 3.5, 1.5, 7.5)
        Pollutant_2 = c(4, 1.3, 2.5, 3.5)
        Year = c(2000, 2001, 2004, 2003)
        
        df = data.frame(Year , Pollutant_1,  Pollutant_2)
        
            # Plot 
            # Make a legend vector
            legend = expression(Pollutant_1~"(ug/m)"^{3},
                                      Pollutant ~"Matter 2.5 (ug/m)"^3)
            
            gg = ggplot(df, aes(x = Year)) +
              geom_line(aes(y = Pollutant_1, color = Pollutant_1),size = 1) +
              geom_point(aes(y = Pollutant_1)) +
              scale_color_discrete(labels = legend) +
              geom_line(aes(y = Pollutant_2, color = Pollutant_2), size = 1) +
              geom_point(aes(y = Pollutant_2)) +
                               labs(x = "Date",
                                    y = "Concentration", 
                                    title = "Title",
                                    color = "Legend",
                                    caption = str_wrap("big caption."))

# Interactive 
ggplotly(gg)

这是一个已知问题。

在此处可以找到短字幕的解决方法:. For the (MANY) plotly annotation options see this documentation

对于较长的字幕,您需要设置一些边距以便写入。此处说明:

很想知道是否有人有更好的方法。