'Plotly not displaying the labs caption from ggplot

I have this code for making a ggplot, which works fine (MRE with a built-in dataset):

mydata <- airquality
avg <- mean(mydata$Wind)
stde <- sd(mydata$Wind)
qup <- qnorm(p = 0.95,mean = avg, sd = stde)
qdown <- qnorm(p = 0.05,mean = avg, sd = stde)
N95 <- length(mydata$Wind[mydata$Wind < qup & mydata$Wind > qdown])
mydata$date <- as.Date(paste(mydata$Month,"-",mydata$Day,sep = ""),format = "%m-%d")

library(ggplot2)
g <- ggplot(mydata, aes(x = date, y = Wind)) + geom_point(aes(colour = "measurements"),pch = 16) +
  geom_hline(aes(yintercept = avg,colour = "mean"),lty = "solid",lwd = 1.2) +
  geom_hline(aes(yintercept = qup,colour = "95%-quantile"),lty = "dotted",lwd = 1.2) +
  geom_hline(aes(yintercept = qdown,colour = "5%-quantile"),lty = "dotted",lwd = 1.2) +
  scale_colour_manual(name = "", values = c(measurements = "deepskyblue4",mean = "goldenrod","95%-quantile" = "goldenrod","5%-quantile" = "goldenrod"),
                      guide = guide_legend(override.aes = list(linetype = c("blank","solid","dotted","dotted"), shape = c(16,NA,NA,NA)))) +
  ylab("Wind [mph]") + xlab("date") + ggtitle("wind speed") +
  scale_y_continuous(limits = c(0,25)) +
  labs(caption = paste("N = ", length(mydata$Wind), "; Mean = ", round(avg,digits = 3), "; Sd = ", round(stde,digits = 3), "; N within limits = ", N95, sep = "")) +
  theme(axis.line.x.bottom = element_line(size=1.5),axis.line.y.left = element_line(size=1.5),plot.title = element_text(hjust = 0.5), axis.title = element_text(size = rel(1.4)),legend.text = element_text(size = rel(1.4)),legend.title = element_text(size = rel(1.3)),axis.text = element_text(size = rel(1.2)))

print(g)

However when I want to make this plot interactive by calling print(plotly::ggplotly(g)), the caption defined in labs is not displayed. Any ideas what causes this or how to fix it?

Many thanks!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source