私はdfを持っています:
Year Ratio N Mean sd se ci
97 1867 TILLBANK...PLACTILL 2 3.861999 4.082170 2.886530 36.67685
98 1867 TILLOBL..PLACTILL 2 21.848833 17.859532 12.628596 160.46153
99 1867 TILLLOAN.PLACTILL 2 54.197044 23.309360 16.482207 209.42629
100 1867 TILLEQUI.PLACTILL 2 0.000000 0.000000 0.000000 0.00000
101 1867 TILLCONT.PLACTILL 2 0.000000 0.000000 0.000000 0.00000
102 1867 TILLRECI.PLACTILL 2 10.772286 5.110514 3.613679 45.91615
str(df) :
'data.frame': 1152 obs. of 7 variables:
$ Year : Factor w/ 156 levels "1855","1856",..: 13 13 13 13 13 13 13 13 14 14 ...
$ Ratio: Factor w/ 8 levels "TILLBANK...PLACTILL",..: 1 2 3 4 5 6 7 8 1 2 ...
$ N : num 2 2 2 2 2 2 2 2 2 2 ...
$ Mean : num 3.86 21.85 54.2 0 0 ...
$ sd : num 4.08 17.86 23.31 0 0 ...
$ se : num 2.89 12.63 16.48 0 0 ...
$ ci : num 36.7 160.5 209.4 0 0 ...
1)私は:をやっていggplot
ます
qqs<-ggplot(dfccomp, aes(x=Year, y=sd,colour=Ratio))+geom_point()+
facet_grid(Ratio~.)+
theme(axis.text.x = element_text(angle=-90, hjust=0.5, size=11,colour="black"))
このプロットはで動作しますgeom_point()
が、現在はで動作しgeom_line()
ます。私が使用する場合、私はgeom_point()
すべての年(1867年から2010年まで)で非常に厄介なx軸を取得します:
そして、私が使用した場合geom_line()
、これは機能しません、私は得ます:
それで、x軸に存在する特定の年だけを選択することがどのように可能であるのだろうか?
2)私が理解していない他の奇妙なことは、df$Year
上記を数値に変換した場合です。
df$Year=as.numeric(as.character(df$Year))
プロットは次のとおりです。
現在、x軸には3年しかありません。どちらが良いですが、それでも私が望むものではありません...
なぜ両方がgeom_point()
機能geom_line()
するのですか?
更新:以下の回答で、「年は要因であり、ggplot()はそれに応じてそれを解釈し、ドットプロットを生成します。このgeomはデータに意味がないため、geom_line()は何もしません。供給;因子の性質は、x軸が連続しておらず、その軸上の点の間に描画するものがないため、線がないことをggplot()に示します。」
geom_line()
しかし、私はある因子で機能する別のプロットを持っています。なんでそうなの?
qq<-ggplot(df, aes(x=Year, y=Mean,colour=Ratio)) +
geom_errorbar(aes(ymin=Mean-sd, ymax=Mean+sd), colour="black", width=.1, position=position_dodge(.1)) +
geom_line(position=position_dodge(.1)) +
geom_point(position=position_dodge(.1), size=3, shape=21, fill="white") + # 21 is filled circle
xlab("Year") +
ylab("Mean (%)")+ggtitle("Ratios")+facet_grid(Ratio~.)+theme(axis.text.x = element_text(angle=-90, hjust=0.5, size=11,colour="black"))
絵: