base-graphics-r-gallery-aez

Home

r-logo.png

Figure 1

Keywords:

png("fig01.png")

plot(iris[iris$Species == "setosa", ]$Sepal.Length,
     iris[iris$Species == "setosa", ]$Petal.Length,
     col = "red", pch = 1,
     xlab = "Sepal Length", ylab = "Petal Length",
     xlim = range(iris$Sepal.Length), ylim = range(iris$Petal.Length))
points(iris[iris$Species == "versicolor", ]$Sepal.Length,
       iris[iris$Species == "versicolor", ]$Petal.Length,
       col = "green", pch = 2)
points(iris[iris$Species == "virginica", ]$Sepal.Length,
       iris[iris$Species == "virginica", ]$Petal.Length,
       col = "blue", pch = 3)
legend(6.5, 3,
       title = "Species",
       legend = c("Setosa", "Versicolor", "Virginica"),
       col = c("red", "green", "blue"),
       pch = c(1, 2, 3),
       bg = "orange")

dev.off()

Figure 2

Keywords:

png("fig02.png")

x <- seq(0, 2, length.out = 100)
foo <- function(x) x
bar <- function(x) exp(-(x - 1)^2) * sin(x * 8)
points_data <- data.frame(x = seq(0, 2, length = 10), y = rnorm(10))
plot(x, foo(x), type = "l", col = "blue", xlim = c(0, 2), ylim = c(-1.5, 1.5), 
     xlab = "x", ylab = "y", main = "Function", cex.main = 1.5)
lines(x, bar(x), col = "red")
points(points_data$x, points_data$y, col = "green")
legend("topright", legend = c("Foo", "Bar", "Baz"), lty = 1, col = c("blue", "red", "green"), 
       cex = 0.8, title = expression(bold(italic("Function"))))

dev.off()

Figure 3

Keywords:

png("fig03.png")

data(faithful)

par(bg = "lightgrey")
hist(faithful$waiting,
     main = expression(italic("Waiting Time between Eruptions")), 
     breaks = seq(40, 100, by = 5),
     xlab = NULL, ylab = NULL,
     col = "blue", border = "orange", bg = "grey")
axis(side = 1, col.axis = "blue", col = "orange")
title(xlab = "Waiting Time (mins)",
      col.lab = "orange", line = 3)
axis(side = 2, col.axis = "orange", col = "green")
title(ylab = "Frequency",
      col.lab = "green", line = 3)

dev.off()

Figure 4

Keywords:

png("fig04.png")

data(iris)

par(bg = "lightblue", mar = c(5, 4, 4, 2) + 0.1)

boxplot(iris$Sepal.Length ~ iris$Species,
        main = "Distribution of Sepal Length in Iris Dataset",
        col.main = "purple",
        xlab = expression(italic("Species")),
        ylab = "Sepal Length (cm)",
        col = "purple",
        border = "red",
        notch = TRUE,
        boxwex = 0.5,
        staplewex = 0.5,
        outpch = 16,
        outcol = "blue",
        horizontal = FALSE)

dev.off()

Figure 5

Keywords:

png("fig05.png")

nrows <- 5
ncols <- 5
data <- matrix(runif(nrows * ncols), nrow = nrows)
rownames <- as.character(5:9)
colnames <- letters[1:5]

heatmap(data, 
        Rowv = TRUE, # include row dendrogram
        Colv = NA,
        xlab = "X Axis Label", 
        ylab = "Y Axis Label",
        main = expression(bold(italic("Main Title"))),
        labRow = rownames, 
        labCol = colnames,
        col = heat.colors(256))

dev.off()

Author: Alexander E. Zarebski

Created: 2023-04-14 Fri 19:37

Validate