0

The following code creates faceted control charts with free scales, thanks to the qicharts2 package.

library(qicharts2)
library(tidyverse)

(plot1 <- qic(age,
              data    = tail(cabg, 100), 
              chart   = 'i',
              title   = 'Age of the last 100 patients (I chart)',
              ylab    = 'Years',
              xlab    = 'Patient #',
              facet   = ~ gender, 
              scales  = 'free'))
p1 <- plot1$data

Capture1.png

When I go ahead and customize the ggplot with my own code (see below) I get almost exactly what I want. But, the scales won't free as seen below. Why can't I get them to free like they are above? The Male facet want to stay stuck on the Female facets scales.

ggplot(p1, aes(x, y)) +
  geom_ribbon(ymin = p1$lcl, ymax = p1$ucl, fill = "black", alpha = 0.05) +
  geom_line(color = "black", size = 1) + 
  geom_line(aes(x, cl)) +
  geom_point(color = "black" , fill = "black", size = 2) +
  geom_point(data = p1 %>% filter(sigma.signal == TRUE), color = "red", size = 2) + 
  ggtitle(label = NULL) +
  labs(x = NULL, y = NULL) +
  facet_grid(~ facet1, scales = "free") + 
  theme_bw() + 
  theme(
    text = element_text(size = 18), 
    axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 0.6), 
    axis.text.y = NULL, 
    panel.grid.major = element_blank(), 
    panel.grid.minor = element_blank(), 
    strip.text.x = element_text(size = 14, color = "black", angle = 0))

Capture2.png

stackinator
  • 5,429
  • 8
  • 43
  • 84

0 Answers0