第10.3章のHadley Wickhamのggplot2の本では、プロット関数の作成を暗に示しています。ファセットを使用する類似のプロットをたくさん作成したいが、列を参照することはできない。すべての私の参照が美学の中にあるなら、私はaes_stringを使うことができ、すべてが機能します。 Facet_wrapはアナログを持っていないようです。ggplotとaes_stringを使ったプロット関数の作成
library(ggplot2)
data(iris)
これは機能化したいプロットです。
pl.flower1 <- ggplot(data=iris,
aes_string(x='Sepal.Length', y='Sepal.Width', color='Petal.Length')) +
geom_point() +facet_wrap(~Species)
これは機能しない場合に機能します。
「sp」は2行下にする必要がありますか?数式、文字列ですか?たぶん全体の問題は間違っています。
flowerPlotWrap <- function(dat, sl, sw, pl, sp){
ggplot(data=dat, aes_string(x=sl, y=sw, color=pl)) + geom_point() +facet_wrap(sp)
}
pl.flower3 <- flowerPlotWrap(iris, sl='Sepal.Length', sw='Sepal.Width', pl='Petal.Length', sp= ?????)
回答に加えて、誰かがどのようにこの問題に近づいているかについてのポインタが大好きです。
この問題を解決する方法については、まず[StackOverflow](http://stackoverflow.com/questions/8043247/writing-r-functions-with-optional-arguments)をチェックしてください。 :) – joran
こちらもお尋ねください:http://stackoverflow.com/questions/11028353/passing-string-variable-facet-wrap-in-ggplot-using-r –