plotly / plotly/plotly.R

ggplotly can omit geom_lines when they are colour coded within groups

Open
#1,153 1 comment 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug ggplotly
Dominant language
R
Stars
2.7k
Forks
641
PR merge metrics
No merged PRs in 30d

Description

Create a ggplot graph in which geom_line objects connect data points within a grouping variable and when colour is also mapped to a variable. i.e. the output is a grid of dots in which dots at the same height are connected by horizontal lines:

ggplot_output

When passed to the ggplotly function, however, the lines are often omitted. In the reproducible example below, all the lines are omitted, but in other examples, sometimes just individual lines fail to plot. In this example, lines, but not points, do appear in the legend:

ggplotly_output

To isolate the problem, in the example below, if the colour = time parameter is dropped from the aes() function, then the lines (in monochrome) do get displayed.

library(ggplot2)
library(dplyr)
library(plotly)

# a dataframe with multiple values per case:
d = data.frame(case = as.factor(rep(1:5, each = 4)),
               time = as.factor(rep(1:4, times = 5)))

p = d %>% 
  ggplot(aes(x = time, y = case, colour = time)) +
  # produce lines to link points within a case: 
  geom_line(aes(group = case)) + 
  geom_point()

print(p) # standard ggplot output includes both lines and points
 
ggplotly(p) # but plotly output omits lines when colour is specified

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproducible R example using ggplotly(), geom_line(), geom_point(), and colour mapped to time; compare its output with the monochrome-line variant. Trace how ggplotly converts grouped geom_line layers, then verify that all grouped lines appear when colour is mapped and that points and legends remain correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data-visualization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.