Skip to content

plotly: legends are truncated when orientation = "h" and margin = list ( l = anyNumber) #1521

@ehb022

Description

@ehb022

Legends are truncated when using orientation = "h" and setting any value for the left margin. This is the only instance where this has occured, and it's a bit of a problem when we want to adjust the left margin. I'm guessing it's a bug?

Example:

# loading dplyr
library(dplyr)
# some data. create factor variable with longer names (Diet)
ChickWeight2 <- ChickWeight %>% 
  ungroup() %>% 
  mutate(Diet = factor (Diet,labels =c("diet 1","diet 2", "diet 3", "diet 4" ))) %>%
  mutate(Time = as.Date(Time, origin = "2010-11-21")) %>% 
  group_by(Time , Diet) %>% 
  summarise(weight = mean(weight)) 


# No problems here, when we don't set any value for the left margin.
plotly::plot_ly(ChickWeight2, x = ~Time, y = ~weight, color = ~Diet,
                type ="scatter",
                mode="line",
                colors = c("red","blue","green", "orange")) %>% 
  plotly::layout(legend = list (orientation="h"),
                 xaxis = list (title=FALSE)  ,
                 margin=list())
                
# Now with left margin, all legends are sometimes in one row (as in this example), and "diet 4" is truncated
plotly::plot_ly(ChickWeight2, x = ~Time, y = ~weight, color = ~Diet,
                type ="scatter",
                mode="line",
                colors = c("red","blue","green", "orange")) %>% 
  plotly::layout(legend = list (orientation = "h"),
                 xaxis = list (title = FALSE)  ,
                 margin=list(l = 0))

Nice plot (first example):
Rplot02

Not nice plot (2nd example):
Rplot01

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions