标题居中的空白图 R

Empty Plotly with centered title R

我正在尝试创建一个空的 plotly,并以一条消息说明该图为何为空作为标题。我想将消息水平和垂直居中。

我错过了垂直中心:

empty_plot <- function(title = NULL){
  p <- plotly_empty(type = "scatter", mode = "markers") %>%
    config(
      displayModeBar = FALSE
    ) %>%
    layout(
      title = title
    )
  return(p)
}

empty_plot("Why it is empty")

刚刚找到选项 yref = "paper",中间位置为 y = 0.5

empty_plot <- function(title = NULL){
  p <- plotly_empty(type = "scatter", mode = "markers") %>%
    config(
      displayModeBar = FALSE
    ) %>%
    layout(
      title = list(
        text = title,
        yref = "paper",
        y = 0.5
      )
    )
  return(p)
} 
empty_plot("Why it is empty")