I have problems with qic charts - control charts. my x.axis does not plot all the dates I want. I rounded the dates to every 14 days, and the period is of 59 weeks. I want all of these plotted, yet I have issues around that and could not find anything on that online. Yet, I am new to the control charts.
Here is an example, not the original data though, so the number of weeks are less here in this example but it does not matter as long as all dates are plotted.
Reproducing the data:
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
And plotting
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")
I have tried with ggplot2 yet, I have not succeeded.
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