0
votes

I have a data frame, where the first column (x) are numbers from 1:12, and second column (y) contains the numbers I want to plot.

I want to create a plot_ly plot of the y axis vs the 12 months. I want to label the x axis as 'Jan', 'Feb', 'Mar, ... 'Dec'.

I have tried:

p <- p %>% plot_ly(df, x = df[[1]]) %>% 
add_lines(y = df[[2]], name = colnames(df)[2]) %>% 
  layout(
    title = " Graph",
    xaxis = list(title="x axis"),
    yaxis = list(title="Y axis")
)

Here the x axis is labeled as 0,1,2,...12.

I have also tried to create a third column in the data frame where the third column contains c('Jan', 'Feb', ... 'Dec'). When I do:

p <- p %>% plot_ly(df, x = df[[3]]) %>% 
add_lines(y = df[[2]], name = colnames(df)[2]) %>% 
  layout(
    title = " Graph",
    xaxis = list(title="x axis"),
    yaxis = list(title="Y axis")
)

the x axis is labeled in alphabetical order as 'Apr', 'Aug', 'Dec', 'Feb', 'Jan', 'Jun', Jul', 'Mar', 'May', 'Nov', 'Oct', 'Sep'.

How can I label the x axis in the chronological order of months for my plot?

1

1 Answers

0
votes

The question is addressed in the following link: https://plot.ly/r/line-charts/ under the section 'Filled Lines'.