plot 各種パラメータを使って,グラフを細かく調整する. 点と折れ線の重ね合わせ,タイトル付け, x,y値の範囲,対数目盛り,xy比,グラフィックパラメータ(点の色や大きさや形,線の色やスタイルや太さ)を調整する.
【外部ページへのリンク】
R システムの CRAN の URL: https://cran.r-project.org/
【サイト内の関連ページ】
R システムの CRAN の URL: https://cran.r-project.org/
plot() 関数には次のような機能がある
主なオプション
平滑化の関数は,他にも,smooth.spline(), ksmooth(), supsmu() などが知られている.
まずは,plot() 関数を使い,x, y 値を指定しての散布図の作成を行う.
x 値を格納したベクトル,y 値を格納したベクトルを引数として plot() 関数を使うと,散布図が描かれます.
plot( c(1, 2, 3, 4, 5, 6, 7, 8), c(3, 3, 4, 4, 2, 3, 4, 5) )
plot( c(1, 2, 3, 4, 5, 6, 7, 8), c(3, 3, 4, 4, 2, 3, 4, 5), type="l" );
plot( c(1, 2, 3, 4, 5, 6, 7, 8), c(3, 3, 4, 4, 2, 3, 4, 5), type="b" );
plot( c(1, 2, 3, 4, 5, 6, 7, 8), c(3, 3, 4, 4, 2, 3, 4, 5), type="c" );
plot( c(1, 2, 3, 4, 5, 6, 7, 8), c(3, 3, 4, 4, 2, 3, 4, 5), type="o" );
main と sub を使用. メインタイトルはグラフの上に,サブタイトルはグラフの下に書かれる.
plot( c(1, 2, 3, 4, 5, 6, 7, 8), c(3, 3, 4, 4, 2, 3, 4, 5), main="散布図タイトル", sub="散布図サブタイトル" )
plot( c(1, 2, 3, 4, 5, 6, 7, 8), c(3, 3, 4, 4, 2, 3, 4, 5) ) legend(5, legend=c("x", "y"))
xlab と ylab を使用.
plot( c(1, 2, 3, 4, 5, 6, 7, 8), c(3, 3, 4, 4, 2, 3, 4, 5), xlab="x軸のタイトル", ylab="y軸のタイトル" )
expression オブジェクトを使う.
X <- seq(1, 5, length=100) Y <- exp(-.5 * log( X^2 ) ) plot(X, Y, type="o", xlab="x", ylab=expression(e^{-frac(1,2) * {log[10](x)}^2}) )
plot( c(1, 2, 3, 4, 5, 6, 7, 8), c(3, 3, 4, 4, 2, 3, 4, 5), xlim=c(0,10), ylim=c(0,6) )
plot( c(1, 2, 3, 4, 5, 6, 7, 8), c(3, 3, 4, 4, 2, 3, 4, 5), asp="0.4" )
plot( c(1, 2, 3, 4, 5, 6, 7, 8), c(3, 3, 4, 4, 2, 3, 4, 5), log="x" )
plot( c(1, 2, 3, 4, 5, 6, 7, 8), c(3, 3, 4, 4, 2, 3, 4, 5), log="y" )
plot( c(1, 2, 3, 4, 5, 6, 7, 8), c(3, 3, 4, 4, 2, 3, 4, 5), log="xy" )
plot( c(1, 2, 3, 4, 5, 6, 7, 8), c(3, 3, 4, 4, 2, 3, 4, 5), panel.first=grid(8,8) )
plot( c(1, 2, 3, 4, 5, 6, 7, 8), c(3, 3, 4, 4, 2, 3, 4, 5), panel.first = lines(stats::lowess( c(8, 7, 6, 5, 4, 3, 2, 1), c(3, 3, 4, 4, 2, 3, 4, 5) ), lty="dashed") )
plot( c(1, 2, 3, 4, 5, 6, 7, 8), c(3, 3, 4, 4, 2, 3, 4, 5), type="o", col="red" )
plot( c(1, 2, 3, 4, 5, 6, 7, 8), c(3, 3, 4, 4, 2, 3, 4, 5), type="o", pch = 0 )
X = c(1, 2, 3, 4, 5, 6, 7, 8) Y = c(3, 3, 4, 4, 2, 3, 4, 5) plot(X,Y,pch = ifelse(Y<4, 0, 1))
plot( c(1, 2, 3, 4, 5, 6, 7, 8), c(3, 3, 4, 4, 2, 3, 4, 5), type="o", cex=4 )
plot( c(1, 2, 3, 4, 5, 6, 7, 8), c(3, 3, 4, 4, 2, 3, 4, 5), type="o", lty=2 )
plot( c(1, 2, 3, 4, 5, 6, 7, 8), c(3, 3, 4, 4, 2, 3, 4, 5), type="o", lty=3 )
plot( c(1, 2, 3, 4, 5, 6, 7, 8), c(3, 3, 4, 4, 2, 3, 4, 5), type="o", lty=4 )
plot( c(1, 2, 3, 4, 5, 6, 7, 8), c(3, 3, 4, 4, 2, 3, 4, 5), type="o", lty=5 )
plot( c(1, 2, 3, 4, 5, 6, 7, 8), c(3, 3, 4, 4, 2, 3, 4, 5), type="o", lwd=4 )