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,210 points

edited Jun 9 by MD 4,533 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 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 5, 2018 in Data Analytics by kappa3010
• 2,090 points
336 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
• 32,490 points
462 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 5, 2019 in Data Analytics by anonymous
8,050 views
+3 votes
2 answers

How to sum a variable by group in R?

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

answered Jul 31, 2019 in Data Analytics by Cherukuri
• 32,490 points
43,131 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
98 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
168 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,580 points

edited Jun 9 by MD 1,772 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
469 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
11,774 views