I am trying to color estimates and intervals as either black (if lower bound of interval is above 1) or gray (if lower bound of interval is below 1). Here is my code:
p <- ggplot(plot.data)+ scale_y_continuous(breaks = c(0, 1, 2),labels = c("1","2.7","7.4"),name="Odds Ratio")
p <- p + geom_hline(yintercept = 0, colour = gray(1/2), lty = 2)
p <- p + geom_pointrange(aes(x = DV, y = Estimate, ymin = Lower,
ymax = Upper),
lwd = 1/2, position = position_dodge(width = 1/2),
shape = 16,color=ifelse(plot.data$Lower<0,"gray60","black")) #+ facet_grid(Missing ~.)+ theme_classic()
p <- p + xlab(label="Predictor Variable") + theme(axis.text.x=element_text(angle=45,hjust=1,vjust=.6))+theme(strip.text.x = element_blank())
p <- p + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) + facet_grid(vars(Missing),vars(Number),scales = "free_x",space="free_x")
p
For some reason, this code only partially works:
Specifically, there are a couple cases that don't seem to be adhering to the rule. For example, look at "PT" as a predictor variable in the lower row. This is colored black even though the lower bound of the interval crosses zero.
There doesn't seem to be any issues with the upper row, so is this maybe some problem with applying the rule with facet_grid
? That is, it doesn't apply the rule equally to all facets?
EDIT: This has been solved. See the comment section below.