[R] How to change x axes labels in plot_ly?

John Kane jrkr|de@u @end|ng |rom gm@||@com
Sun Jun 23 15:56:21 CEST 2019


Could you supply some code and sample data. The data should be in
dput() format. The way the data has arrived is very difficult to read.

I have never heard of ploty. Is that a typo?

To answer your direct question, yes you should be able to change the
x-axis labels but we need to get some idea of what exactly you are
doing before we can easily suggest a solution.

I would recommend reading this two links to get an idea of how to
present a question in order to get the besc reply
http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example

 http://adv-r.had.co.nz/Reproducibility.html

On Thu, 20 Jun 2019 at 11:05, <nstefi using gmail.com> wrote:
>
> Hi everyone,
>
>
>
> I have been struggling with this for a while, and I hope someone can give me
> some advice.
>
> I have built a line chart that shows a cumulated value of number of
> transactions, and there are 2 lines on the chart comparing last year with
> this year.
>
> The way I matched last year's data with this year's data is by the month and
> day (without the year), so my data looks like this:
>
>
> Month-Day
>
> FiscalYear_Days
>
> Last_year
>
> This_Year
>
>
> 05-01
>
> 0
>
> 16
>
> 10
>
>
> 05-02
>
> 1
>
> 17
>
> 14
>
>
> 05-03
>
> 2
>
> 22
>
> 18
>
>
> 05-04
>
> 3
>
> 25
>
> 18
>
>
>
> chart_data <- matrix(c("05-01", "05-02", "05-03", "05-04",
>
>                 "0", "1", "2", "3",
>
>                 "16", "17", "22", "25",
>
>                 "10", "14", "18", "18"),
>
>                 nrow=4, ncol=4, dimnames=list(c("A","B","C","D"),
> c("Month-Day","FiscalYear_Days", "Last_year", "This_Year")))
>
>
>
> Since our fiscal year doesn't start on January 1st, I had to introduce this
> column called "FiscalYear_Days", which is the number of days passed since
> 1st day of fiscal year, and matched last year and current year by that
> instead. Otherwise I had a problem with plot_ly() showing the chart starting
> with January 1st on the left.
>
>
>
> Now I figured out a way to change the order of the x axis labels to make it
> based on the "FiscalYear_Days" instead. This is a simplified plot:
>
> plot_ly(renewals_chart_data,
>
>         x = ~`Month-Day`,
>
>         y = ~Last_Year,
>
>         type = 'scatter',
>
>         mode = 'lines'
>
> ) %>%
>
>   layout(xaxis = list(categoryarray = renewals_chart_data$FiscalYear_Days,
> categoryorder = "array"))
>
>
>
> My problem now is that if the period is longer than 1 year, under Month-Day
> column I will have some repeating values starting from following year May
> 1st (05-01, 05-02, etc.), and the plotly chart shows an increasing line that
> returns back to the left side when reaches the next year's May 1st.
>
> How can I make the line to continue on the right?
>
> If I change plotly to show the x axis based on "FiscalYear_Days", the line
> is right, but I want at the bottom to show the month and day as labels:
>
> plot_ly(renewals_chart_data,
>
>         x = ~`FiscalYear_Days`,
>
>         y = ~Last_Year,
>
>         type = 'scatter',
>
>         mode = 'lines'
>
> ) %>%
>
>   layout(xaxis = list(categoryarray = renewals_chart_data$FiscalYear_Days,
> categoryorder = "array"))
>
>
>
> Is it possible to just change the x axis label values?
>
>
>
> Thanks a lot,
>
> Steven
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
John Kane
Kingston ON Canada



More information about the R-help mailing list