R ggplotly: legend is not displayed correctly

I have a problem with the plotly package. The legend does not display correctly or does not display all the values ​​caused by its slice!

enter image description here

I would like to get a legend outside the plot area (in the bottom or right corner).

I already tried changing position in ggplot :

 legend.position="bottom" 

no result at all ...

then I tried the code from plotly :

 p %>% layout(legend = list(x = 0.5, y = -100)) 

it didn’t work, the legend was at the bottom, but it was cut out, and behind the name of the x axis ...

Here is a sample code from the mtcars :

 a <- ggplot(mtcars, aes(x = interaction(cyl, carb, lex.order = T), y = mpg,fill = interaction(cyl, carb, lex.order = T))) + geom_boxplot() ggplotly(a) 

as we can see that the name of the legend is also cut there.

I would be grateful for any help!

thanks

+5
source share
1 answer

You can play with field size and size. You can try:

 m = list( l = 100, r = 40, b = 100, t = 50, pad = 0 ) a <- ggplot(mtcars, aes(x = interaction(cyl, carb, lex.order = T), y = mpg,fill = interaction(cyl, carb, lex.order = T))) + geom_boxplot() a %>% layout(autosize = F, width = 800, height = 600, margin = m) 
+5
source

Source: https://habr.com/ru/post/1246400/


All Articles