参照頻度が高いので個人的メモ。
①plot関数におけるグラフ種別設定パラメーターについて。
- type="p"...点プロット(デフォルト)
- type="l"...線プロット(折れ線グラフ)
- type="b"...点と線のプロット
- type="c"..."b" において点を描かないプロット
- type="o"...点プロットと線プロットの重ね書き
- type="h"...各点から x 軸までの垂線プロット
- type="s"...左側の値にもとづいて階段状に結ぶ
- type="S"...右側の値にもとづいて階段状に結ぶ
- type="n"...軸だけ描いてプロットしない(続けて低水準関数でプロットする場合)
#統計言語Rでの確認例
plot(1:10, 1:10, type="n",main="For Drawing area", axes = FALSE,xaxt="n",yaxt="n",xlab="", ylab="",xaxt="n",yaxt="n")
#ダミーのグラフ描写
#type="p"
plot(seq(-5, 5, length=5),seq((-5+15), (5+15), length=5) ,xlim=c(-5,5),ylim=c(-5,20),type="p",lty =1,main="Proting type", xlab="Dots & lines", ylab="Proting type")
#type="l"
par(new=T) # 上書き指定
plot(seq(-5, 5, length=5) ,seq((-5+13),(5+13), length=5), xlim=c(-5,5),ylim=c(-5,20),type="l",lty =1,main="", xlab="", ylab="")
#type="b"
par(new=T) # 上書き指定
plot(seq(-5, 5, length=5) ,seq((-5+11),(5+11), length=5), xlim=c(-5,5),ylim=c(-5,20),type="b",lty =1,main="", xlab="", ylab="")
#type="c"
par(new=T) # 上書き指定
plot(seq(-5, 5, length=5) ,seq((-5+9),(5+9), length=5), xlim=c(-5,5),ylim=c(-5,20),type="c",lty =1,main="", xlab="", ylab="")
#type="o"
par(new=T) # 上書き指定
plot(seq(-5, 5, length=5) ,seq((-5+7),(5+7), length=5), xlim=c(-5,5),ylim=c(-5,20),type="o",lty =1,main="", xlab="", ylab="")
#type="h"
par(new=T) # 上書き指定
plot(seq(-5, 5, length=5) ,seq((-5+5),(5+5), length=5), xlim=c(-5,5),ylim=c(-5,20),type="h",lty =1,main="", xlab="", ylab="")
#type="s"par(new=T) # 上書き指定
plot(seq(-5, 5, length=5) ,seq((-5+3),(5+3), length=5), xlim=c(-5,5),ylim=c(-5,20),type="s",lty =1,main="", xlab="", ylab="")#type="S"
par(new=T) # 上書き指定
plot(seq(-5, 5, length=5) ,seq((-5-3),(5-3), length=5), xlim=c(-5,5),ylim=c(-5,20),type="S",lty =1,main="", xlab="", ylab="")
#type="s"
plot(seq(-5, 5, length=5) ,seq((-5+3),(5+3), length=5), xlim=c(-6,6),ylim=c(-6,6),type="s",lty =1,main="Proting type", xlab="Dots & lines", ylab="Proting type")#type="S"
par(new=T) # 上書き指定
plot(seq(-5, 5, length=5) ,seq((-5-3),(5-3), length=5), xlim=c(-6,6),ylim=c(-6,6),type="S",lty =1,main="", xlab="", ylab="")
②同じくplot関数における凡例の位置パラメーターは以下。
#統計言語Rでの確認例
plot(1:10, 1:10, type="n",main="Position of the legend", xlab="", ylab="",xaxt="n",yaxt="n")#ダミーのグラフ描写
legend("topleft",legend="topleft")
legend("top",legend="top")
legend("topright",legend="topright")
legend("left",legend="left")
legend("center",legend="center")
legend("right",legend="right")
legend("bottomleft",legend="bottomleft")
legend("bottom",legend="bottom")
legend("bottomright",legend="bottomright")
③同じくplot関数の凡例で使う点マーカーはpch引数、線種はIty引数で与える。
#統計言語Rでの確認例
plot(1:30, 1:30, type="n",main="The type of points and lines", xlab="", ylab="",xaxt="n",yaxt="n")#ダミーのグラフ描写
legend("topleft",legend=c(1:25),pch=c(1:25),lty =c(1:25),ncol=5)
④「対数目盛り」の導入について
#統計言語Rでの確認例
Diameters<-c(1392000,4879,12104,12756,6794,142984,120536,51118,49572)
names(Diameters)<-c("Sun","Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus" ,"Neptune")
Diametersstr(Diameters)
#グラフ化
barplot(Diameters, main="The diameters of the planets",xlab = "Planets", ylab = "Diameters")#惑星名が歯抜けになってしまったので、X軸とY軸のラベルを縦表示に。
barplot(Diameters,las = 2, main="The diameters of the planets",xlab = "Planets", ylab = "Diameters")#今度はX軸で描写領域重複が起こったのでY軸のラベルを消す。
barplot(Diameters, las = 2, main="The diameters of the planets",xlab = "Planets", ylab = "")
#太陽が巨大過ぎて他の惑星間の比較が困難なのでY軸に対数目盛り導入。
barplot(Diameters, las = 2, log="y",main="The diameters of the planets",xlab = "Planets", ylab = "")
*目盛りが「ゴミ一色」となってかえって分かり難くなってしまった感も。まさかの「Exelの方が隠蔽工作は完璧」という現実…これが何かについての解説は別途追加予定。
#アニメーション描写による問題解決を試みる。やはりY軸目盛りには「ゴミ」が出るがとりあえず無視。
library("animation")
The_diameters_of_the_planets<-function(ylimits){
barplot(Diameters, las = 2, ylim=c(0,ylimits),main="The diameters of the planets",xlab = "Planets", ylab = "")
}Time_Code=c(100000,200000,400000,600000,800000,1000000,1200000,1400000,1200000,1000000,800000,600000,400000,200000)
saveGIF({
for (i in Time_Code){
The_diameters_of_the_planets(i)
}
}, interval = 0.1, movie.name = "TEST.gif")
*統計言語RにおけるGIFアニメーション作成方法は以下参照の事。
以下続報…