図に文字や線を描く
文字と線の描画
図のなかに文字を書き込んだり、直線を描きます。
plot(c(0,0), xlim=c(0,10), ylim = c(0,8), type = "n")
text(5, 1, 'lwd = 1, lty = "solid", col="black"')
lines(c(1, 10), c(0.9, 0.9), lwd = 1 , lty = "solid", col = "black")
text(5, 2, 'lwd = 2, lty = "dashed", col = "red"')
lines(c(1, 10), c(1.9, 1.9), lwd = 2, lty = "dashed", col = "red")
text(5, 3, 'lwd = 3, lty = "longdash", col = "green"')
lines(c(1, 10), c(2.9, 2.9), lwd = 3, lty = "longdash", col = "green")
text(5, 4, 'lwd = 4, lty = "solid", col = "grey"')
lines(c(1, 10), c(3.9, 3.9), lwd = 4, lty = "solid", col = "blue")
text(5, 5, 'lwd = 3, lty = "dotdash", col = "blue"')
lines(c(1, 10), c(4.9, 4.9), lwd = 3, lty = "dotdash", col = "magenta")
text(5, 6, 'lwd = 2, lty = "twodash", col = "brown"')
lines(c(1, 10), c(5.9, 5.9), lwd = 2, lty = "twodash", col = "brown")
text(5, 7, 'lwd = 1, lty = "dotted", col = "magenta"')
lines(c(1, 10), c(7, 7), lwd = 1, lty = "dotted", col = "grey")
曲線を描く
曲線の数式を設定すれば、同じlinesで曲線を描くこともできます。
plot(c(0,0), xlim=c(0,10), ylim = c(0,8), type = "n")
x <- seq(0, 10, 0.01)
y <- (-0.3)*(x - 1)*(x - 8) + 1 #例えば負の二次関数とします。
lines(x, y) #上に凸の曲線になりましたね。
exp()の括弧内はべき乗です。ためしにexp(1)を試してください。
y <- 8/(1+exp(-x+4))
lines(x, y, lty=2)