Search code examples
rplotlytidyverse

How to plot using plotly in R


https://drive.google.com/file/d/1dZzu5BPVtzP4y6Leb6712-1C_hBPXjX_/view?usp=sharing

I'm trying to create a interactive bar plot using ploty in R. The link contains the dataset that I'm working.

This is my code but the output is totaly different from what expected

df<- read.csv("continental_death_total.csv")


fig <- df %>%
  plot_ly(
    x = ~continent,
    y = ~continental_sum,
    frame = ~date,
    type = 'bar',
    mode = 'markers',
    showlegend = F
  )

fig

Output Output


Solution

  • You could use the following code with type = "bar" (Click on the play button to see the bars on each date):

    df<- read.csv("continental_death_total.csv")
    
    library(dplyr)
    library(plotly)
    fig <- df %>%
      plot_ly(
        x = ~continent,
        y = ~continental_sum,
        frame = ~date,
        type = 'bar',
        showlegend = F
      )
    
    fig
    

    Output:

    enter image description here


    You can check the docs for more information and examples.