Using barplot
Here plot.heights
is a matrix:
> plot.heights
[,1] [,2]
[1,] 74 91
[2,] 26 9
When barplot takes in a 2D data structure, like this, it plots each row as a group.
(Last time, we saw what it does for a 1D structure: simply plot all of them one after the other.)
The return value bp
is the same shape as our input data. It tells us where on the x-axis each of the bar centers is.
bp <- barplot(
plot.heights,
beside = T,
names = c("GMO germ.","Wild germ.",
"GMO fail", "Wild fail"),
ylim = c(0, max(plot.heights) + 20),
ylab = "Number of seeds")
Using barplot
Here plot.heights
is a matrix:
> plot.heights
[,1] [,2]
[1,] 74 91
[2,] 26 9
When barplot takes in a 2D data structure, like this, it plots each row as a group.
(Last time, we saw what it does for a 1D structure: simply plot all of them one after the other.)
The return value bp
is the same shape as our input data. It tells us where on the x-axis each of the bar centers is.
bp <- barplot(
plot.heights,
beside = T,
names = c("GMO germ.","Wild germ.",
"GMO fail", "Wild fail"),
ylim = c(0, max(plot.heights) + 20),
ylab = "Number of seeds")