I have the following ggplot
How can I displace the red (or blue, doesn't matter) horizontal errorbar a bit up or down from the horizontal grey line in order to make a better visualisation for the reader?
Code comes here
set.seed(121)
Varnames <- c("Age", "Weight", "Length") # Variable names
uVarvalues <- runif(3, 1, 5) # Univariate Odds ratios
uspread <- runif(3, 1, 2) # Confidence intervals
uCI_hi <- uVarvalues + uspread/2 # Upper level of CIs
uCI_lo <- uVarvalues - uspread/2 # Lower level of CIs
mVarvalues <- runif(3, 1, 5) # Multivariate Odds ratios
mspread <- runif(3, 0, 2) # Confidence intervals
mCI_hi <- mVarvalues + mspread/2 # Upper level of CIs
mCI_lo <- mVarvalues - mspread/2 # Lower level of CIs
library(ggplot2)
vertline <- c(1) # preparing vertical lines to be shown in graph
ggplot(data=NULL, aes(x=uVarvalues, y=Varnames)) +
geom_point(aes(x=uVarvalues, y=Varnames), shape=18, color="deepskyblue3", size=3) +
ylab(NULL) +
xlab(NULL) +
geom_vline(xintercept = vertline,
size=0.1
) +
geom_errorbarh(
aes(xmin=uCI_lo, xmax=uCI_hi),
size=.6,
height=0.1,
colour="deepskyblue3",
linetype="solid"
) +
geom_point(aes(x=mVarvalues, y=Varnames), shape=18, color="firebrick", size=3) +
geom_errorbarh(
aes(xmin=mCI_lo, xmax=mCI_hi),
size=.6,
height=0.1,
colour="firebrick",
linetype="solid"
) +
scale_x_log10(
breaks = c(0.2,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15),
labels = c("0.2", "1", "2", "", "","5","","","","", "10", "","","","","15"),
limits = c(0.2,15)
) +
theme(
panel.background = element_blank(),
axis.ticks.y = element_blank(),
panel.grid.major.x = element_blank(),
panel.grid.major.y = element_line(size = 0.25, linetype = 'solid', colour = "grey"),
panel.grid.minor.x = element_blank(),
panel.grid.minor.y = element_blank(),
axis.text.x = element_text(family="Georgia", size=10),
axis.text.y =element_text(family="Courier New", size=10, face="bold")
)
Thank you