How to plot side-by-side Plots with ggplot2 in R

0 votes

Like we are creating two plots of the dataset "iris":

Boxplot:

data("iris")
library(ggplot2)

iris1 <- ggplot(iris, aes(x = Species, y = Sepal.Length)) +
  geom_boxplot() + theme_bw()

BarPlot:

iris2 <- ggplot(iris, aes(x = Sepal.Length, fill = Species)) +
  geom_bar() + theme_bw() +
  theme(legend.position = c(0.8, 0.8))

But we want to plot these two graphs together to compare.

Apr 16, 2018 in Data Analytics by DataKing99
• 8,250 points

edited Jun 9, 2020 by MD 8,837 views

1 answer to this question.

0 votes

By Using gridExtra library we can easily plot with grid.arrange()

require(gridExtra)
gridExtra::grid.arrange(iris1,iris2)

There is another way to put it together by using cowplot library, as grid.arrange makes it difficult to labels the plots with letters(A, B, C,....)

library(cowplot)
plot_grid(iris1, iris2, labels = "AUTO")
answered Apr 16, 2018 by DeepCoder786
• 1,720 points

edited Jun 9, 2020 by MD

Related Questions In Data Analytics

0 votes
1 answer

How to join two tables (tibbles) by *list* columns in R

You can use the hash from digest ...READ MORE

answered Apr 6, 2018 in Data Analytics by kappa3010
• 2,090 points
1,701 views
+1 vote
2 answers

How to sort a data frame by columns in R?

You can use dplyr function arrange() like ...READ MORE

answered Aug 21, 2019 in Data Analytics by anonymous
• 33,030 points
1,812 views
0 votes
2 answers

How to use group by for multiple columns in dplyr, using string vector input in R?

data = data.frame(   zzz11def = sample(LETTERS[1:3], 100, replace=TRUE),   zbc123qws1 ...READ MORE

answered Aug 6, 2019 in Data Analytics by anonymous
14,090 views
+4 votes
3 answers

How to sum a variable by group in R?

You can also try this way, x_new = ...READ MORE

answered Aug 1, 2019 in Data Analytics by Cherukuri
• 33,030 points
78,148 views
0 votes
1 answer
0 votes
0 answers

Chart/plot to show 3 dimensions in a chart - R

Hi, I want to show chart with ...READ MORE

Jul 12, 2019 in Data Analytics by kalyan
543 views
0 votes
0 answers

Kmeans Clusters - R visualization

Hi, can someone help me visualizae the ...READ MORE

Aug 1, 2019 in Data Analytics by rajeev
834 views
0 votes
1 answer

Aligning title in ggplot2

You can use the theme layer to ...READ MORE

answered Apr 27, 2018 in Data Analytics by Bharani
• 4,660 points

edited Jun 9, 2020 by MD 3,739 views
0 votes
1 answer

How to convert a text mining termDocumentMatrix into excel or csv in R?

By assuming that all the values are ...READ MORE

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,919 views
0 votes
3 answers

How to write lines to a text file in R?

sink("outfile.txt") cat("hello") cat("\n" ...READ MORE

answered May 24, 2019 in Data Analytics by anonymous
19,012 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP