plotly / plotly/plotly.R

ggplotly not working with control chart library ggQC

Open
#2,177 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

Brief description of the problem:

Adding some lines and labels using the ggQC library causes a hard fail.

This code works with ggplotly:

      min_date = as.Date(min(lots_df_filtered()$DATE))
      max_date = as.Date(max(lots_df_filtered()$DATE))
      if (!is.na(min_date)) {
        num_days = length(seq(from = min_date, to = max_date, by = 'day')) - 1
        date_breaks <- if(num_days <= 31) 'day' else 'week'
        XmR_Plot <- 
            ggplot(lots_df_filtered(), aes(x = as.Date(DATE), y = YRS_YIELD)) +
            geom_point(alpha = .5) + geom_line() +
            labs(title=paste0(input$mfg_step_name, ' Lot Yield Control Chart')) +
            scale_x_date(date_breaks=date_breaks) +
            theme_ipsum_ps() +
            theme(axis.text.x = element_text(angle = 60, vjust = 0.5, hjust=1),
                  axis.title.x=element_blank()) 
        output$lot_time_series <- renderPlotly(ggplotly(XmR_Plot))
      }`

Produces a nice chart as so:

image

The following code results in an error (alpha must be of length 1 or the same length as x):

      min_date = as.Date(min(lots_df_filtered()$DATE))
      max_date = as.Date(max(lots_df_filtered()$DATE))
      if (!is.na(min_date)) {
        num_days = length(seq(from = min_date, to = max_date, by = 'day')) - 1
        date_breaks <- if(num_days <= 31) 'day' else 'week'
        XmR_Plot <- 
            ggplot(lots_df_filtered(), aes(x = as.Date(DATE), y = YRS_YIELD)) +
            geom_point(alpha = .5) + geom_line() +
            stat_QC(method = "XmR",      
                    auto.label = T, 
                    label.digits = 2,   
                    show.1n2.sigma = T   
                    ) +
            labs(title=paste0(input$mfg_step_name, ' Lot Yield Control Chart')) +
            scale_x_date(date_breaks=date_breaks) +
            theme_ipsum_ps() +
            theme(axis.text.x = element_text(angle = 60, vjust = 0.5, hjust=1),
                  axis.title.x=element_blank()) 
        output$lot_time_series <- renderPlotly(ggplotly(XmR_Plot))
      }

Here is what the ggplot looks like when I do not use ggplotly and do use ggCC:

image

Could this be related to the ggplotly argument layerData? Any help is appreciated.

thx

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 by running the supplied R reproduction with ggplotly, ggplot2, and ggQC, comparing the working plot with the version using stat_QC(). Investigate the reported “alpha must be of length 1 or the same length as x” failure and confirm the control-chart layers render through ggplotly without the hard fail.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.