0

我正在使用该qicharts2()包在 R 中构造一个 p 图。必须有一个变量 UCL / LCL,但qic()本机构造它的方式不是我想要的。请看以下两张图片:

什么qic()产生: 在此处输入图像描述

我需要它来生产: 在此处输入图像描述

我不确定如何更改此设置,并且在帮助小插图中找不到太多可以帮助控制 UCL/LCL 的内容。任何有关如何控制这些美学或对其进行计算的帮助表示赞赏(我不是统计学家)。样本:

df <- data.frame(Date = sample(seq(as.Date('1999/01/01'), as.Date('2000/01/01'), by="day"), 25), 
                 Values = sample(seq(from = 0, to = 1, by = .1), size = 25, replace = TRUE), 
                 Totals = sample(seq(from = 0, to = 50, by = 1), size = 25, replace = TRUE))

qic(data = df, y = Values, x = Date, n = Totals, chart = 'p', point.size = 2)
4

1 回答 1

0

感谢@markus 的评论,关键是将qic()gg 对象保存到变量并访问图层。使用下面的代码演示了它是如何工作的:


df <- data.frame(Date = sample(seq(as.Date('1999/01/01'), as.Date('2000/01/01'), by="day"), 25), 
                 Values = sample(seq(from = 0, to = 1, by = .1), size = 25, replace = TRUE), 
                 Totals = sample(seq(from = 0, to = 50, by = 1), size = 25, replace = TRUE))

p <- qic(data = df, y = Values, x = Date, n = Totals, chart = 'p', point.size = 2, show.labels = TRUE, decimals = 0) +
  geom_line(color = "steelblue") + theme_bw() +
  ylim(c(0,1)) +
  ggtitle("Sample qic() Plot") +
  xlab("") +
  ylab("") +
  theme(plot.title = element_text(hjust = 0.5, size = 16, face = "bold"), 
        axis.title.y = element_text(face = "bold", size = 12)) +
  theme(axis.text.x = element_text(angle = 65, hjust = 1, size = 12, face = "bold"), 
        axis.text.y = element_text(size = 12, face = "bold")) +
  theme(legend.position = "none")

p$layers[[1]] <- NULL; 
p$layers <- c(p$layers, geom_step(data = p$data, aes(y = ucl), linetype = "dotted", col = "grey50", size = 1), geom_step(data = p$data, aes(y = lcl), linetype = "dotted", col = "grey50", size = 1)); 
p

输出:

在此处输入图像描述

于 2019-06-05T19:14:08.413 回答