I would like to change the big number separator from comma to blank in plotly. I can do this in ggplot2, but not in plotly. It should probably be done through tickformat option (https://plotly.com/r/reference/#layout-xaxis-tickformat), but after trying some d3-format as specified here : https://github.com/d3/d3-format/blob/master/README.md I don't get it.
For exemple, in the following graph :
diamonds %>%
plot_ly(x=~clarity,y=~~depth*10000) %>%
add_bars()
I don't want to have "50K", "40K" on the y axis, but "50 000", "40 000".
If I add
layout(yaxis=list(tickformat=","))
I get "50,000", "40,000" ...
If I add
layout(yaxis=list(tickformat=" "))
I get "50000","40000"...
But I can't get a blank space separator.
layout(yaxis=list(tickformat=","))
Try this approach formating labels and text with tickvals
and ticktext
in layout
. You can create your breaks with a sequence and then formating it to have the desired outcome. Here the code:
library(plotly)
#Labels
ticklabels <- seq(from=0, to=round(max(diamonds$depth*10000)), by=10000)
ticktexts <- c(0,paste(ticklabels[-1]/1000, " 000", sep=""))
#Code
diamonds %>%
plot_ly(x=~clarity,y=~~depth*10000) %>%
add_bars() %>%
layout(yaxis=list(tickvals = ticklabels,
ticktext = ticktexts
))
Output: