Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Empty Plotly with centered title R

Tags:

r

plotly

r-plotly

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")
like image 986
Clemsang Avatar asked Jun 27 '19 09:06

Clemsang


1 Answers

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")
like image 58
Clemsang Avatar answered Nov 02 '22 23:11

Clemsang