Adam_G
Adam_G

Reputation: 7879

Change legend size in plotly chart

Is there a way to change the legend size in plotly for R? I have not come across this option. I have looked at the docs on legends, https://plot.ly/r/legend/, but it does not mention this.

Upvotes: 22

Views: 51425

Answers (2)

Sesha
Sesha

Reputation: 139

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.

Upvotes: 13

Ma Tusiaczek
Ma Tusiaczek

Reputation: 186

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

Upvotes: 17

Related Questions