I have a plotly barplot in a shiny app, showing factor levels on X axis. But on some number of inputs (2,3,4) it shows marks like 1.5, 2.5 etc (see an image). So there is a question: can I somehow make the X axis marks show only integer values?
How do you remove gridlines in Plotly? Toggling Axis grid lines Axis grid lines can be disabled by setting the showgrid property to False for the x and/or y axis.
Short answer is about 250,000 x-y points.
In this example, we are hiding legend in Plotly with the help of method fig. update(layout_showlegend=False), by passing the showlegend parameter as False.
plotly
is guessing your axis types since your cluster labels are numeric. You can fix this by coercing your x var to a factor before/when plotting.
library(plotly)
library(dplyr)
mtcars_by_gear <- count(mtcars,gear)
plot_ly(mtcars_by_gear,
x=~as.factor(gear),
y=~n)
If you want further control over axis labels you can use the layout()
function's tick arguments, but the factor option seems better for your case.
plot_ly(mtcars_by_gear,
x=~gear,
y=~n,
type="bar") %>%
layout(xaxis=list(tickvals=~gear,ticktext=~gear))
tickformat=',d'
Supposing the attributes are the same as in Python where I tested :-), you can set:
layout(xaxis=list(tickformat=',d'))
where the valid values are D3 formats.
See also: https://community.plot.ly/t/restrict-axis-ticks-labels-to-only-show-int-values/3503/4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With