NIM : 210605110007
Lembaga: “Universitas Islam Negeri Maulana Malik Ibrahim Malang”
Fakultas: “Sains dan Teknologi”
Jurusan: “Teknik Informatika”
legend(x, y=NULL, legend, fill, col, bg)
Catatan: x dan y: koordinat yang digunakan untuk posisi legend. legend: teks pada legend
fill: warna yang digunakan untuk mengisi box disamping teks legend.
col: warna garis dan titik disamping teks legend.
bg: warna latar belakang legend box.
Berikut adalah contoh sintaks dan ouput penerapan argumen:
# membuat vektor numerik
x <- c(1:10)
y <- x^2
z <- x*2
# membuat line plot
plot(x,y, type="o", col="red", lty=1)
# menambahkan line plot
lines(x,z, type="o", col="blue", lty=2)
# menambahkan legend
legend(1, 95, legend=c("Line 1", "Line 2"),
col=c("red", "blue"), lty=1:2, cex=0.8)
a. title: Judul legend
b. text.font: integer yang menunjukkan font style pada teks legend. Nilai yang dapat dimasukkan adalah sebagai berikut:
- 1: normal
- 2: cetak tebal
- 3: cetak miring
- 4: cetak tebal dan miring.
- bg: warna background legend box.
Berikut adalah penerapan sintaks dan output yang dihasilkan:
# membuat line plot
plot(x,y, type="o", col="red", lty=1)
# menambahkan line plot
lines(x,z, type="o", col="blue", lty=2)
# menambahkan legend
legend(1, 95, legend=c("Line 1", "Line 2"),
col=c("red", "blue"), lty=1:2, cex=0.8,
title="Line types", text.font=4, bg='lightblue')
Berikut adalah penerapan argumen tersebut beserta output yang dihasilkan:
# membuat line plot
plot(x,y, type="o", col="red", lty=1)
# menambahkan line plot
lines(x,z, type="o", col="blue", lty=2)
# menambahkan legend
legend(1, 95, legend=c("Line 1", "Line 2"),
col=c("red", "blue"), lty=1:2, cex=0.8,
title="Line types", text.font=4, bg='white',
box.lty=2, box.lwd=2, box.col="steelblue")
Sejumlah kustomisasi legend berdasarkan keyword adalah:
# plot
plot(x,y, type = "n")
# posisi kiri atas, inset =0.05
legend("topleft",
legend = "(x,y)",
title = "topleft, inset = .05",
inset = 0.05)
# posisi atas
legend("top",
legend = "(x,y)",
title = "top")
# posisi kanan atas inset = .02
legend("topright",
legend = "(x,y)",
title = "topright, inset = .02",
inset = 0.02)
# posisi kiri
legend("left",
legend = "(x,y)",
title = "left")
# posisi tengah
legend("center",
legend = "(x,y)",
title = "center")
# posisi kanan
legend("right",
legend = "(x,y)",
title = "right")
# posisi kiri bawah
legend("bottomleft",
legend = "(x,y)",
title = "bottomleft")
# posisi bawah
legend("bottom",
legend = "(x,y)",
title = "bottom")
# posisi kanan bawah
legend("bottomright",
legend = "(x,y)",
title = "bottomright")