使用geom_text在错误栏旁边添加文本

时间:2017-02-16 20:58:02

标签: r ggplot2

如何使用geom_text()在每个上部错误栏旁边添加“数字”字段。即在上部错误栏的右侧。

 group= 1:10
count = c(41,640,1000,65,30,4010,222,277,1853,800 )
mu = c(.7143,.66,.6441,.58,.7488,.5616,.5507,.5337,.5513,.5118)
sd = c(.2443,.20,.2843,.2285,.2616,.2365,.2408,.2101,.2295,.1966)
u = mu + 1.96*sd/sqrt(count)
l=  mu - 1.96*sd/sqrt(count)
number = c(23,12,35,32,23,63,65,66,66,66)
dat = data.frame(group= group, count = count, mu = mu, sd = sd,u,u,l=l,number = number)
dat[order(dat$count),]



ggplot(dat,  aes(y=factor(group), x=  mu)) +
  geom_point()+
  geom_errorbarh(aes(xmax = as.numeric(u),xmin = as.numeric(l)))

1 个答案:

答案 0 :(得分:2)

  • func scrollDown() { let scrollView = webview.scrollView let contentSize = scrollView.contentSize let contentOffset = scrollView.contentOffset let frameSize = webview.frame.size let frameHeight = frameSize.height // Next view's height let heightOffset = frameSize.height + contentOffset.y let offsetToBottom = contentSize.height - frameSize.height if contentOffset.y + frameHeight > contentSize.height - frameHeight { scrollView.setContentOffset(CGPoint(x: 0, y: offsetToBottom), animated: true) print("Should be scrolling to bottom") } else { scrollView.setContentOffset(CGPoint(x: 0, y: heightOffset), animated: true) print("Should be scrolling by one page") } } 使用数字作为标签,上部错误栏使用x坐标。 y坐标将与您在aes(label = number, x = as.numeric(u))中指定的相同。
  • ggplot将证明文本标签的合理性并将其正确移动。
  • 使用hjust = -1调整可能超出右边缘的文字。

示例:

xlim()

enter image description here