如何使用GGR中的ggplot替换(红色)水平错误条以实现更轻松的可视化?

如何使用GGR中的ggplot替换(红色)水平错误条以实现更轻松的可视化?,r,ggplot2,errorbar,R,Ggplot2,Errorbar,我有下面的情节 如何将红色(或蓝色,无所谓)的水平错误条从水平灰线向上或向下移动一点,以便为读者提供更好的可视化效果 这里有密码 set.seed(121) Varnames <- c("Age", "Weight", "Length") # Variable names uVarvalues <- runif(3, 1, 5) # Univariate Odds ratios uspread <- runif(3, 1, 2)

我有下面的情节

如何将红色(或蓝色,无所谓)的水平错误条从水平灰线向上或向下移动一点,以便为读者提供更好的可视化效果

这里有密码

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")
  )
set.seed(121)

Varnames是你的朋友

更新内容包括OP关于移动积分的建议


#`position=position_-nudge()`是你的朋友:
种子(121)

Varnames是你的朋友

更新内容包括OP关于移动积分的建议


#`position=position_-nudge()`是你的朋友:
种子(121)

Varnames这可能很有用这可能很有用很好,很有效,我在
geom\u point
中添加了
position\u-nudge
,使点以同样的方式排列。当然,我希望我能想到这一点!对这个问题的关注太过文字化。太好了,这很有效,我在
geom\u point
中添加了
position\u-nudge
,使点以同样的方式排列。当然,我希望我能想到这一点!对这个问题的关注太过火了。