Change legend size in plotly chart

While working with legends, there are two pieces to configure.

  1. Legend title (legend_title parameter)
  2. Actual legend (legend parameter)

Let's say you already have a fig(it can be mostly any plot), to that add below line with parameters as you wish, in separate dictionaries.

fig.update_layout(legend = dict(font = dict(family = "Courier", size = 50, color = "black")),
                  legend_title = dict(font = dict(family = "Courier", size = 30, color = "blue")))

This way you will have more control over two thing.


Use layout(legend = list(font = list(size(30)))):

plot_ly(data = mtcars, x = as.character(mtcars$cyl), 
        y = mtcars$mpg, type = "box", color = as.character(mtcars$cyl)) %>%
    layout(showlegend = TRUE, legend = list(font = list(size = 30)))

Tags:

R

Plotly