これらの質問(1)と(2)を見ましたが、ここでの質問とは関係がないようです。
最初にリボンを作成し(for ループの外側)、for ループ内に一連の線と点のプロットを追加しようとしています。ただし、最終的なプロットには、最後の for ループからの線/点のみが含まれ、すべてではありません。このコード全体は関数内にあり、関数から ggplot(この場合は p) オブジェクトを返して、後で使用できるようにしたいと考えています。
hist_points_cols_val<-hist_points_cols(hist_points)
hist_points_labels_val<-hist_points_labels(hist_points)
p <- ggplot()+
geom_ribbon(aes(x = x_labels , ymin = Min , ymax = Max),data=t_out_summary,colour = '#ece9d8',fill = '#ff9999',alpha = 0.4)+
geom_ribbon(aes(x = x_labels , ymin = Qtr1 , ymax = Qtr3),data=t_out_summary,colour = '#ece9d8',fill = '#33ff99',alpha = 0.2)+
scale_x_discrete(name=scale_x, labels=plot_labels)+
scale_y_continuous(name=scale_y, labels = percent_format())+
geom_line(aes(x = x_labels,y = Median,colour="Median"),data=t_out_summary)+
geom_point(aes(x = x_labels,y = Median,colour="Median"),data=t_out_summary,shape=4)
print(hist_points_cols_val)
print(hist_points_labels_val)
for( i in 1: length(hist_points)){
p <- p + geom_line(aes(x = x_labels,y = t_out_summary[[hist_points_cols_val[i]]],colour=hist_points_labels_val[i]),data=t_out_summary,linetype='dashed')+
geom_point(aes(x = x_labels,y = t_out_summary[[hist_points_cols_val[i]]],colour=hist_points_labels_val[i]),data=t_out_summary,shape=4)
}
p<-p+scale_colour_hue(name="Legend")
データは次のようになります。
`> str(t_out_summary)
'data.frame': 12 obs. of 11 variables:
$ Min : num 0.121 0.132 0.145 0.164 0.172 ...
$ Qtr1 : num 0.154 0.165 0.174 0.191 0.2 ...
$ Median : num 0.184 0.195 0.203 0.218 0.225 ...
$ Qtr3 : num 0.22 0.231 0.238 0.249 0.253 ...
$ Max : num 0.398 0.381 0.37 0.351 0.339 ...
$ p_1D : num 0.16 0.169 0.176 0.197 0.207 ...
$ p_2D : num 0.153 0.163 0.171 0.193 0.204 ...
$ p_1W : num 0.168 0.179 0.187 0.204 0.215 ...
$ p_2W : num 0.141 0.154 0.163 0.184 0.196 ...
$ p_1M : num 0.146 0.157 0.165 0.186 0.201 ...
$ x_labels: int 1 2 3 4 5 6 7 8 9 10 ...`
最小、最大ポイントを使用してリボンを作成し、p_1D、p_2D のポイントとラインを追加したいと考えています。ggplot2 グラフィックスを助長する方法とはどういう意味ですか? 異なるプロットを重ねるために for ループを使用しています。forループなしでどうやってそれを行うのですか?