いくつかのオプションがあります
ベース R の使用
plot.function
メソッド(curve
関数をプロットするために呼び出す)を使用できます。これは、あなたが呼び出す場合に呼び出されるものですplot(functionname)
これが機能するように、おそらく独自の関数をロールする必要があります。ylim
また、両方の機能の全範囲が表示されるように を設定する必要があります。
# for example
fooX <- function(x) dnorm(x, mean = 0.05, sd = 0.1)
plot(fooX, from = -0.25, to = 0.35)
# I will leave the definition of fooY as an exercise.
fooY <- function(x) {# fill this is as you think fit!}
# see what it looks like
plot(fooY, from = -0.25, to = 0.35)
# now set appropriate ylim (left as an exercise)
# bonus marks if you work out a method that doesn't require this!
myYLim <- c(0, appropriateValue)
# now plot
plot(fooX, from = -0.25, to = 0.35, ylim = myYLim)
# add the second plot, (note add = TRUE)
plot(fooY, from = -0.25, to = 0.35, add = TRUE)
ggplot2 の使用
ggplot
プロットに関数stat_function
を課す関数があります。の例は、?stat_function
平均が異なる 2 つの正規 pdf 関数を同じプロットに追加する方法を示しています。