R 转换为plotly时保留ggplot2引用

R 转换为plotly时保留ggplot2引用,r,ggplot2,plotly,r-plotly,R,Ggplot2,Plotly,R Plotly,我必须创建一组图,我已经使用ggplot2制作了它们。我希望通过将它们转换为plotly,使它们具有交互性。但是,我遇到了一些格式问题。这些问题中最烦人的是,我似乎无法保留我在情节底部创建的引用 下面是一些重现错误的代码: Names = c("eggs","milk","bread","I need to make some names longer") Kilos = c("1","2","3","4") df= as.data.frame(cbind(Names,Kilos)) plo

我必须创建一组图,我已经使用ggplot2制作了它们。我希望通过将它们转换为plotly,使它们具有交互性。但是,我遇到了一些格式问题。这些问题中最烦人的是,我似乎无法保留我在情节底部创建的引用

下面是一些重现错误的代码:

Names = c("eggs","milk","bread","I need to make some names longer")
Kilos = c("1","2","3","4")
df= as.data.frame(cbind(Names,Kilos))


plot_citation = "I need to include the citation for my data in the plot itself. 
Some of the citations are long, so they
take up
several lines."


TestGGPlot = ggplot(df,aes(y = Kilos, x = Names, fill = Names))+
geom_bar(stat = "identity")+
scale_fill_manual(values = c("#ABCABC","#ABCABC","#ABCABC","#ABCABC"))+
theme(legend.position = "none")+
coord_flip()+
xlab("Names")+
ylab("Kilos")+

theme(panel.grid.major = element_blank(),panel.grid.minor = element_blank(),panel.background = element_blank(),axis.ticks.y=element_blank())+ 

 labs(caption = plot_citation,vjust=1,hjust=1)+
 theme(plot.caption=element_text(hjust=0))



TestGGPlot



TestPlotly = ggplotly(TestGGPlot)
TestPlotly
ggplot如下所示:

plotly图形如下所示:

我通过调整绘图的域并在其下方添加注释,将引用包含在绘图图中,但我无法在这里实现这一点。我不知道使用“ggplotly”函数创建的绘图是否与普通的plotly绘图行为不同,或者我只是不完全理解plotly语法

谢谢大家!