Skip to content

Control legends of individual plots within subplots #826

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kickbox opened this issue Dec 14, 2016 · 3 comments
Closed

Control legends of individual plots within subplots #826

kickbox opened this issue Dec 14, 2016 · 3 comments

Comments

@kickbox
Copy link

kickbox commented Dec 14, 2016

With the subplots approach I want to achieve the following

  • Not group all legends into one legend -> Each legend should be within its own pot area
  • Don't add legends when the individual ggplotly object doesnt have one.

Data

df <- structure(list(Tool = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 3L, 
                                        3L), .Label = c("ToolA", "ToolB", "ToolC"), class = "factor"), 
                     StartTime = structure(c(1456383600, 1464291720, 1456383600, 
                                             1460710380, 1464291780, 1456383600, 1456383600, 1460710380
                     ), class = c("POSIXct", "POSIXt"), tzone = "MET"), Category = structure(c(1L, 
                                                                                               2L, 3L, 1L, 2L, 3L, 4L, 4L), .Label = c("C1", "C2", "C3", 
                                                                                                                                       "null"), class = "factor"), Type = structure(c(4L, 2L, 2L, 
                                                                                                                                                                                      3L, 3L, 2L, 1L, 1L), .Label = c("null", "T1", "T2", "T3"), class = "factor")), .Names = c("Tool", 
                                                                                                                                                                                                                                                                                "StartTime", "Category", "Type"), row.names = c(NA, -8L), class = "data.frame")

> df
   Tool           StartTime Category Type
1 ToolA 2016-02-25 08:00:00       C1   T3
2 ToolA 2016-05-26 21:42:00       C2   T1
3 ToolA 2016-02-25 08:00:00       C3   T1
4 ToolB 2016-04-15 10:53:00       C1   T2
5 ToolB 2016-05-26 21:43:00       C2   T2
6 ToolB 2016-02-25 08:00:00       C3   T1
7 ToolC 2016-02-25 08:00:00     null null
8 ToolC 2016-04-15 10:53:00     null null

Plotly Code

pOne <- ggplotly(ggplot(data=df[df$Tool=="ToolA",],aes(x=StartTime ,y= Tool, colour=Type))+
                   geom_point(alpha=0.8,size=4)) %>% layout(legend = list(orientation = 'h'))

pTwo <- ggplotly(ggplot(data=df[df$Tool=="ToolB",],aes(x=StartTime ,y= Tool,colour=Category))+
                    geom_point(alpha=0.8,size=4)) %>% layout(legend = list(orientation = 'h'))

pThree <- ggplotly(ggplot(data=df[df$Tool=="ToolC",],aes(x=StartTime ,y= Tool))+
                    geom_point(alpha=0.8,size=4)) %>%  layout(showlegend = FALSE)

subplot(pOne,pTwo,pThree, nrows=3, shareX= T,which_layout = 1)

Actual Behaviour

Highlighted the legend in red

capture

Expected Behaviour

untitled

Can you please add this feature, as this is essential

  1. To bring intuitiveness to visualisations, otherswise the business users find it complex to understand the plot with flying/ungrouped/wrongly-positioned legends
  2. To control legends' in such a way that they show in the right position and don't show up when not required
@cpsievert
Copy link
Collaborator

@kickbox see this test

@kickbox
Copy link
Author

kickbox commented May 18, 2017

@cpsievert I don't think the referred "test" is relevant for this issue.

@ebigelow
Copy link

Legend groups (as that test uses) don't really solve this problem. Legend groups can add a little extra spacing between legend items for separate plots, but with the cost of being able to show/hide individual traces - a major feature of plotly's legends.

This issue seems to be subsumed by: plotly/plotly.js#1668

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants