带有居中标题 R 的空 Plotly

Cle*_*ang 5 r plotly r-plotly

我正在尝试创建一个空的,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")
Run Code Online (Sandbox Code Playgroud)

Cle*_*ang 6

刚刚找到选项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")
Run Code Online (Sandbox Code Playgroud)