The default behavior of plotly is to scale axes automatically upon toggling a trace. How to counter this behavior?
library(plotly)
library(reshape2)
data("tips")
fig <- plot_ly(tips, x = ~total_bill, y = ~tip, type = 'scatter', mode = 'markers', split = ~sex) %>%
layout( plot_bgcolor='#e5ecf6',
xaxis = list(
zerolinecolor = '#ffff',
zerolinewidth = 2,
gridcolor = 'ffff'),
yaxis = list(
zerolinecolor = '#ffff',
zerolinewidth = 2,
gridcolor = 'ffff'))
fig
CodePudding user response:
An option is to disable the autorange
and specify a range
for both axis like this:
library(plotly)
library(reshape2)
data("tips")
fig <- plot_ly(tips, x = ~total_bill, y = ~tip, type = 'scatter', mode = 'markers', split = ~sex) %>%
layout( plot_bgcolor='#e5ecf6',
xaxis = list(
zerolinecolor = '#ffff',
zerolinewidth = 2,
gridcolor = 'ffff',
autorange = FALSE,
range = c(0, 50)),
yaxis = list(
zerolinecolor = '#ffff',
zerolinewidth = 2,
gridcolor = 'ffff',
autorange = FALSE,
range = c(0, 7)))
fig
Created on 2023-01-19 with reprex v2.0.2
When you click on the legend, you will see that it doesn't autoscale the axis.