Direct plotly plot instead of going through ggplot

is there a direct way to have the plotly plot below, rather than going through the ggplot?

output$plotly1 <- renderPlotly({
      g <- ggplot(testdata, aes(fill=Metrics, y=Percent, x=Date)) +
        geom_bar(position="stack", stat="identity") +
        facet_wrap(~Line, strip.position = "bottom") +
        ylab("Metric Percentage (%)")


that is, something to start with:

output$plotly1 <- renderPlotly({


yes, just like that.

Basic Charts | R | Plotly

What would be inside that plot_ly?

That depends on what plot you are making.
The website link has a gallery of examples. Did you try any ?

yes, I visited the link before, but for my example of stacked + facet_wrap, it seems not easy to do it directly inside plot_ly.

1 Like

Splendid, I will take a look, thanks for much for the link.

I think this is what you are after:

Check out specifically the section titled - Trellis displays with subplot()

This post took a while to get approved. This is the same as what nirgrahamuk shared as well.

I try out this link r - How to facet a plot_ly() chart? - Stack Overflow and try to modify to my needs, but seems it is not straight forward, because I have 3 dimensions (Date, Line, Metrics).

testdata %>%
+   group_by(Metrics) %>%
+   group_map(~ plot_ly(data=., x = ~Date, y = ~Percent, color = ~Metrics, type = "bar"), keep=TRUE) %>%
+   subplot(nrows = 1, shareX = TRUE, shareY=TRUE)

My testdata looks like this:

I'm sure you shared this image with the best intentions, but perhaps you didnt realise what it implies.
If someone wished to use example data to test code against, they would type it out from your screenshot...

This is very unlikely to happen, and so it reduces the likelihood you will receive the help you desire.
Therefore please see this guide on how to reprex data. Key to this is use of either datapasta, or dput() to share your data as code

please download CSV from this link here:

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.