アメリエフの技術ブログ

Amelieff Staff Blog

R 「関数textとlegend 5」

R 「関数textとlegend」では、文字列と凡例を書き込みました。
書きこんだ文字列が見にくいようなので、位置を調節します。
太字の部分を書き足しました。

# デバイス領域
png("110131_iris.png", height=700, width=500)
# 作図領域
par(mar=c(4,4,2,6),xpd=TRUE)
# プロット領域(散布図)
plot(iris[,1], iris[,3], xlab="iris[,1]", ylab="iris[,3]", pch=(15:17)[unclass(iris[,5])], col=rainbow(3)[unclass(iris[,5])], cex=1.5)
# 文字列の描画
names <- c="" 1:150="" br=""> text(iris[,1], iris[,3], names, cex=0.8, pos=4)
# 凡例
legend(8.1, 4, levels(iris[,5]), pch=15:17, col=rainbow(3), cex=1, bg='gray80')
dev.off()



※posについて
1234の順に、下左上右となります。
ここでは、右横に表示させるため「pos=4」にしました。