rggplot2themeslegend

Parameters for the ggplot theme function about legend.axis.line


Does anyone know the main purpose of the parameter legend.axis.line? Feel similar to legend.ticks? And I can't seem to find a use for it yet.

In which case would it be used?

ggplot(mtcars, aes(x = cyl, y = gear, fill = mpg)) +
  geom_tile() +
  theme(
    legend.position = 'top', 
    # legend.ticks = element_line(color='black', linewidth = 5),
    legend.axis.line = element_line(color = 'red', linewidth = 10)
    )

enter image description here


Solution

  • I believe theme(legend.axis.line) is only useful in legends where binned scale was used. Based on the release note for ggplot2 version 3.5.0, I believe we can use this parameter directly in theme instead of using it in guide_bins() as shown in the documentation.

    library(ggplot2)
    
    ggplot(mtcars) +
      geom_point(aes(disp, mpg, size = hp)) +
      scale_size_binned() +
      theme(legend.axis.line = element_line(color = "red", linewidth = 5))
    

    ggplot_output