How to combine 4 bar plots with a 2x2 grid layout in R studio here is my code: #
ID: 3787293 • Letter: H
Question
How to combine 4 bar plots with a 2x2 grid layout in R studio
here is my code:
#Bar plot1
counts <- table(iris2_1_$Sepal.Length)
plot1 <- barplot(counts, main="numerical attributes 1", horiz=TRUE,
names.arg=c("Sepal.Length"))
#Bar plot2
counts <- table(iris2_1_$Sepal.Width)
plot2 <- barplot(counts, main="numerical attributes 2", horiz=TRUE,
names.arg=c("Sepal.Width"))
#Bar plot3
counts <- table(iris2_1_$Sepal.Width)
plot3 <-barplot(counts, main="numerical attributes 3", horiz=TRUE,
names.arg=c("Petal.Width"))
#Bar plot4
counts <- table(iris2_1_$Sepal.Width)
plot4 <- barplot(counts, main="numerical attributes 4", horiz=TRUE,
names.arg=c("Petal.Width"))
Explanation / Answer
just put this command before your plots.
par(mfrow = c(2, 2)) # 3 rows and 2 columns
To put multiple plots on the same graphics pages in R, you can use the graphics parameter mfrow or mfcol. To use this parameter, you need to supply a vector argument with two elements: the number of rows and the number of columns.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.