ggplot2刻面情节 - 不能释放我的音阶

时间:2018-05-25 16:05:23

标签: r ggplot2

以下代码使用qicharts2包创建了具有自由缩放的分面控制图。

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

当我继续使用自己的代码定制ggplot(见下文)时,我几乎可以得到我想要的内容。但是,如下所示,体重秤不会自由。为什么我不能让它们像上面一样自由? Male方面希望坚持Female方面的尺度。

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

0 个答案:

没有答案