简体   繁体   中英

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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM