2017-03-12 4 views
2

これは私が作成したサンプルデータとプロットです。単一要素の複数の点を並べて並べる

library(ggplot2) 
value<-c(-1.01, -0.02,1.61,0.60, -0.98,0.19,4.68,-0.86,-3.52,-1.85,-2.08,-0.48,0.10,-1.05,-0.003) 
sd<-c(1.40,0.48,0.83,0.41,0.80,0.36,1.52,0.30,1.19,0.44,1.33,0.45,0.64,0.35,1.20) 
variable<-rep(c("A","B","C","D","E"),times=3) 
clss<-rep(c("NC","RC","LC"),each=5) 
df<-data.frame(value,variable,clss) 

ggplot(df,aes(x=variable,y = value))+ 
geom_point()+ 
geom_hline(yintercept = 0, size = I(0.2), color = I("red")) + 
geom_errorbar(aes(ymin = value - 1.96 * sd, ymax = value + 1.96 * sd),width = .1) 

enter image description here

それぞれA、B、C、D及びEのための3つの点があるので、私はむしろ、単一の列よりも側によって3点側をプロットします。これはまた、A、B、C、D、Eの3つの点がグラフ上で別々に見えるように、ラベルAとB、BとCとの間にいくらかの間隔が必要であることを意味します。

私はジッタ

enter image description here

を使用しようとしました。しかし、それは私のポイントではなく、私のエラーバーをシフトします。また、私は3点の真ん中にAを配置する必要があります。同様にB、C、DおよびE

+0

さて。私はします。 – user53020

答えて

4

ためあなたがgeom_pointgeom_errorbar両方にdodgeを使用する必要がある:

ggplot(df,aes(x=variable,y = value,group=value,color=variable))+ 
geom_point(position=position_dodge(width=0.5)) + 
geom_hline(yintercept = 0, size = I(0.2), color = I("red")) + 
geom_errorbar(aes(x=variable,ymin = value - 1.96 * sd, ymax = value + 1.96 * sd),width = .1,position=position_dodge(width=0.5)) 

enter image description here