我正在使用qicharts2()
包在R中构造一个p图。有必要有一个变量UCL / LCL,但是qic()
本机构造的方式并不是我想要的。请看下面两张图片:
What qic()
produces:
我需要它来产生的东西:
我不确定如何改变这一点,在帮助小插曲中也找不到太多帮助控制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)
发布于 2019-06-06 03:14:08
感谢@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
输出:
https://stackoverflow.com/questions/56461685
复制相似问题