我正在使用qicharts2()
包在R中构造p图。必须具有可变的UCL / LCL,但是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)
答案 0 :(得分: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
输出: