I have a shiny application which present a scatterplot. The shiny user perform data filtering, then the data is display in the plotly graph. Sometime, the data created will be all negative or all positive, but I still want to plot to be positioned a way that the origin (0,0) is displayed.
Example:
dd <- data.frame(x=c(2,3,6,2), y=c(5,2,7,3))
plot_ly(data=dd, x=~x, y=~y, type="scatter", mode="markers")
gives:
But I want it to look initially more like that:
Any idea how to do that?
Use rangemode:
plot_ly(data=dd, x=~x, y=~y, type="scatter", mode="markers") %>%
layout(
xaxis = list(rangemode = "tozero"),
yaxis = list(rangemode = "tozero"))
This will also work with dd2 <- -1 * dd
:
plot_ly(data=dd2, x=~x, y=~y, type="scatter", mode="markers") %>%
layout(
xaxis = list(rangemode = "tozero"),
yaxis = list(rangemode = "tozero"))
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