package ggplot2 and plotly

Hello,
I made a package which uses the package ggplot2 and plotly.
So when I've made # import ggplot2 and #import plotly in the function and Install&restart I have a warning below :
Is ggplot2 and plotly are compatible?

Warning: replacing previous import ‘ggplot2::last_plot’ by ‘plotly::last_plot’ when loading ‘mypackage’

Have you an idea?
Thanks in advance

Is ggplot2 and plotly are compatible?

Yes. Are you using the last_plot() function in your package? If not, then it's safe to ignore this warning.

1 Like

I didn't use last_plot() in my package. SO, what is this function?

Now my concern is the user. If I leave the warning the user doesn't understand this message.

How I can delete this warning?

You can try importing everything except for last_plot()

Thanks a lot, I used

#' @rawNamespace import(ggplot2, except = last_plot)

and I don't have the warning message;

So, I have other issue.
my mypackage contains one function with ggplot&ggplotly
When I call it, the graph is not represented and there are any error message.
The function (of mypackage)that I calls contain :

....
 p<-ggplot(tab) +
      geom_line(aes(x =tab$cum, y = tab$linkcum )) +
      geom_line(aes(x =tab$flowcum, y = tab$flowcum )) +
        theme(
        panel.background = element_blank(),
        panel.grid.minor = element_blank(),
        panel.grid.major = element_line(color = "gray50", size = 0.5),
        panel.grid.major.x = element_blank(),
        axis.text.y = element_text(colour="#68382C", size = 9))

    ggplotly(p) %>% layout(dragmode = "select")

Is it possible to use ggplot inside a function ?

Thanks in advance to your help!

I've tested mypackage.
When I call library(mypackage) the package ggplot2 and plotly should be called.

library(mypackage)

data<- read.csv2("liste.csv",header=TRUE,sep=";",stringsAsFactors=FALSE,encoding="UTF-8",dec=".",check.names=FALSE)  
p<-function(data,..., g.plot = TRUE)

I have a error message

Error in ggplot(data) : impossible de trouver la fonction "ggplot"

If I understand correctly ggplot2 is not in my package, then I declared it in Namespace
Have you an idea!

Hello
All everything it's ok I ve made @rawimport(plotly except = last_plot) and importFrom ggplot2 wish all functions that I need.
Thanks to your help

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.