1
votes

I want to plot time series in plotly. Dataframe has two columns, date in Date format and number of odrers as integer, for example:

order_created   margin
2017-01-01      7004
2017-02-01      4424
2017-03-01      3792
2017-04-01      6031
2017-05-01      7561
2017-06-01      6903
2017-07-01      6687
2017-08-01      3283
2017-09-01      6683
2017-10-01      4781
2017-11-01      6960

When I am plot data using type = "scatter" & fill = 'tozeroy' I get complete mess:

plot_ly(somedata, 
        x = ~order_created, 
        y = ~margin, 
        name = 'Total margin', 
        type = 'scatter', 
        mode = 'none', 
        fill = 'tozeroy')

enter image description here

When I use the same data and code, but change type to "bar" it creates proper plot:

plot_ly(somedata, 
    x = ~order_created, 
    y = ~margin, 
    name = 'Total margin', 
    type = 'bar', 
    mode = 'none', 
    fill = 'tozeroy')

enter image description here

Any suggestions how to produce proper line (filled area) chart?

Thanks

1
For line charts, try color instead of fill for the line chart.Ryan Morton
If you look at the y values of the bar plot... it's not correct (15K > 7K)C8H10N4O2

1 Answers

0
votes

On plotly 4.7.1, this works fine for me:

# reproducible example!
somedata <- read.table(text=
"order_created   margin
2017-01-01      7004
2017-02-01      4424
2017-03-01      3792
2017-04-01      6031
2017-05-01      7561
2017-06-01      6903
2017-07-01      6687
2017-08-01      3283
2017-09-01      6683
2017-10-01      4781
2017-11-01      6960", header=TRUE,
colClasses = c('Date','numeric'))

library(plotly)
(p <- plot_ly(somedata, 
        x = ~order_created, 
        y = ~margin, 
        name = 'Total margin', 
        type = 'scatter', 
        mode = 'none', 
        fill = 'tozeroy'))

plotly_IMAGE(p, format = "png", out_file = "output.png")

enter image description here