I have a dataframe imported from excel. one of the column is of the format :
dates
-------
Oct-17
Nov-17
Dec-17
Jan-18
Feb-18
Mar-18
Apr-18
May-18
Jun-18
Jul-18
Aug-18
All other columns are just numbers
When I plot it using plotly (line chart), I am getting my x axis in alphabetical order. I tried factor.But it is not working.
data_ = read_excel(path="Sample.xlsx",sheet = 'sheet1')
data = as.data.frame(data_)
data$dates <- factor(data$dates, levels = data$dates)
What has to be done? Finally I need x axis labelled with months in this format Oct-18,Nov-18
plot code :
pred <- plot_ly(data_, x = ~dates, y = ~exp, name = 'Exp', type = 'scatter', mode = 'lines',
line = list(color = 'rgb(205, 12, 24)', width = 4)) %>%
add_trace(y = ~acc, name = 'Accumulated', line = list(color = 'rgb(22, 96, 167)', width = 4)) %>%
add_trace(y = ~sts, name = 'Contract', line = list(color = 'rgb(205, 12, 24)', width = 4, dash = 'dash')) %>%
add_trace(y = ~stat, name = 'Status ', line = list(color = 'rgb(22, 96, 167)', width = 4, dash = 'dash')) %>%
layout(title = "Trend",
xaxis = list(title = "Months"),
yaxis = list (title = "")"))