我对 qic 图表有疑问 - 控制图表。我的 x.axis 没有绘制我想要的所有日期。我将日期四舍五入为每 14 天一次,周期为 59 周。我想要所有这些都被绘制出来,但是我对此有一些问题,并且在网上找不到任何东西。然而,我是控制图的新手。
这是一个示例,但不是原始数据,因此在此示例中此处的周数较少,但只要绘制了所有日期就无关紧要。
重现数据:
df <- data.frame(x = rep(1:24, 4),
ReportMonth = (rep(seq(as.Date('2014-1-1'),
length.out = 24,
by = 'month'),
4)),
num = rbinom(4 * 24, 100, 0.5),
denom = round(runif(4 * 24, 90, 110)),
grp1 = rep(c('g', 'h'), each = 48),
grp2 = rep(c('A', 'B'), each = 24))
df
并作图
qic(x= ReportMonth,
y= num,
n= denom,
data=df,
chart= "i",
x.format="%Y-%m-%d",
x.angle = 90,
y.expand = 40, # where to start y axis from
xlab = "Month",
ylab= "Value")
我已经尝试过 ggplot2 了,我还没有成功。
library(ggplot2)
library(plyr)
p3.1 <- rename(p3, c("x" = "Date"))
p3.1$Date<-as.Date(p3.1$x, format="%Y/%m/%d")
plot4 <- ggplot(p3.1, aes(x = Date,y = y )) +
geom_ribbon(ymin = p3.1$lcl, ymax = p3.1$ucl, alpha = 0.4) + # fill = ""
geom_line(colour = "blue", size = .75) +
geom_line(aes(Date, cl)) +
geom_point(colour = "red" , fill = "red", size = 1.5) +
#x.axis(1, p3$x, format(p3$x, "%Y-%m-%d"), cex.axis = 0.7)+
ggtitle(label = "Readmissions within 30 days") +
labs(x = NULL, y = NULL)+
theme_minimal()+
theme(axis.text.x = element_text(angle = 90, hjust = 1))
#aes(x = format(ActiveDate,"%Y-%m"), group = 1)) + geom_line(stat = "count")
#+ theme(axis.text.x = element_text(angle = 90, hjust = 1))
plot4