减少 y-axis 和绘图 title/axis 之间的 space 刻度

Reducing space between y-axis and plot title/axis ticks

我正在使用 plotly 和以下代码在 R 中输出散点图:

library(tidyverse)
library(plotly)

set.seed(1)

data.frame(state = c(rep(state.name, 2)),
           value = sample(1:100, 100)) %>% 
  plot_ly(x = ~value,
          y = ~state,
          type = "scatter",
          mode = "markers") %>% 
  layout(title = list(text = "State Information"))

我 运行 遇到的问题是上面的代码在 y-axis 和绘图标题和 [=30= 之间呈现了一个 space 过多的绘图]分别打勾:

谁能告诉我如何缩小这个 space 以便情节边距更紧凑?

编辑:我知道这里有人问过类似的问题,但这涉及到数字 y-axis,而不是分类问题:

我们可以使用 作为分类轴。

请 运行 schema() 并导航:object ► layout ► layoutAttributes ► yaxis ► range:

[...] If the axis type is category, it should be numbers, using the scale where each category is assigned a serial number from zero in the order it appears.

library(plotly)
library(datasets)

set.seed(1)

DF <- data.frame(state = c(rep(state.name, 2)),
                 value = sample(1:100, 100))

plot_ly(
  data = DF,
  x = ~ value,
  y = ~ state,
  type = "scatter",
  mode = "markers"
) %>%
  layout(
    title = list(text = "State Information"),
    xaxis = list(
      range = ~ c(-1, length(unique(value)) + 1)
    ),
    yaxis = list(
      range = ~ c(-1, length(unique(state))),
      title = list(text = "state", standoff = 0L)) # maybe needed? sets distance between title and labels
  )