plotly / plotly/plotly.R

[Bug] Geom_smooth graphical error when converting from ggplot to plotly using ggplotly

Open
#1,472 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Hello,

I have a graphical issue which shows up when converting a ggplot2 plot with geom_smooth to a plotly plot:
bugged

as you can see in the plotly plot, an extra nonsensical confidence interval ribbon gets generated below the fitted lines.

When I lower the confidence interval from 0.95 to 0.80 the ribbon in correctly displayed:
ggplotly_correct_but_lower_confinterval

However this is not the confidence interval I need.
I know it has something to do with plotly as this is my ggplot (with confidence interval 0.95) used to generate the first bugged image:
ggplot_correct

Here is the (anonymized) code used to generate the plot(s):

p16 <- ggplot(data= df, order = rownames(x)) +
geom_point(data= df,aes(x=x.ordered, y=(mean1), color=paste("Number = ", Number))) +
geom_point(data= df,aes(x=x.ordered, y=(mean2), color=paste("Number2 = ", Number))) +
geom_smooth(data = dfcopy, aes(x=x.ordered, y=mean2, color=Number, group=Number), method="loess", level=0.95) +
ylab("y") + scale_y_continuous(limits=c(0, 1)) + xlab(paste("x")) +
theme_bw() + theme(plot.title = element_text(hjust = -.5, face="bold"), axis.title.x = element_text(hjust = 1, size = 14, face="bold"), axis.text.x = element_text(angle = 90, hjust = 1), axis.title.y = element_text(size = 14, face="bold")) +
ggtitle("") + labs(color = "\n\nType of data point: " )

p16 <- p16 + scale_color_manual(values=c("#B24745FF", "#DF8F44FF","#00A1D5FF", "#6A6599FF", "#00A1D5FF", "#6A6599FF"))
gp16 <- ggplotly(p16, tooltip=c("text")) %>% layout(legend = list(orientation = "v",xanchor = "center", x = 1.2), title = list())

Unfortunately I can't provide data or the axes, I also removed the ggplot text variable due to anonymous data.

If someone might know a solution to this graphical error, it would be greatly appreciated.

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

No repository file or test is named, and the reporter cannot provide the data or axes. Start at the ggplotly conversion path with a reproducible geom_smooth loess plot using level=0.95, comparing it with the ggplot output. Done means the extra confidence-interval ribbon is no longer generated and the converted plot matches the source plot.

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
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.