How to make plot axes only display integers
2 answers
plotly
guesses the types of your axis since the cluster labels are numeric. You can fix this by coercing your x var to a pre / post ratio. In the meantime, there is no need to know about it. โ
library(plotly)
library(dplyr)
mtcars_by_gear <- count(mtcars,gear)
plot_ly(mtcars_by_gear,
x=~as.factor(gear),
y=~n)
If you need more control over the axis labels, you can use the arguments layout()
to the tick function, but the coefficient option seems better for your case.
plot_ly(mtcars_by_gear,
x=~gear,
y=~n,
type="bar") %>%
layout(xaxis=list(tickvals=~gear,ticktext=~gear))
+4
source to share
tickformat=',d'
Suppose the attributes are the same as in Python where I tested :-) you can set:
layout(xaxis=list(tickformat=',d'))
where D3 formats are valid.
See also: https://community.plot.ly/t/restrict-axis-ticks-labels-to-only-show-int-values/3503/4
+2
source to share