5
votes

I am trying to create an empty plotly with a message telling why the plot is empty as a title. I would like to center the message both horizontally and vertically.

I am missing the vertical center :

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")
1

1 Answers

6
votes

Just found the option yref = "paper", with y = 0.5 for middle position:

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")