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))

image

image But we want to be together as to compare two plots easily!

Apr 16, 2018 in Data Analytics by DataKing99
• 8,100 points
1,164 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)

image

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

library(cowplot)
plot_grid(iris1, iris2, labels = "AUTO")

image
answered Apr 16, 2018 by DeepCoder786
• 1,700 points

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,010 points
42 views
0 votes
1 answer

How to sort a data frame by columns in R?

You can just use the order function ...READ MORE

answered Apr 10, 2018 in Data Analytics by darklord
• 6,140 points
73 views
0 votes
1 answer

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

dplyr added versions for group_by. This allows you ...READ MORE

answered Apr 12, 2018 in Data Analytics by CodingByHeart77
• 3,680 points

edited Apr 12, 2018 by CodingByHeart77 2,218 views
0 votes
1 answer

How to sum a variable by group in R?

Easily by using Aggregate Func(): aggregate(x$points, by=list(Players=x$Players), FUN=sum) or ...READ MORE

answered Apr 13, 2018 in Data Analytics by CodingByHeart77
• 3,680 points

edited Apr 13, 2018 by CodingByHeart77 5,081 views
0 votes
0 answers
0 votes
0 answers

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

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

5 days ago in Data Analytics by kalyan
11 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,550 points
592 views
0 votes
10 answers

Changing the legend title in ggplot

Example : p <- ggplot(mtcars, aes(mpg, wt, colour ...READ MORE

answered Dec 10, 2018 in Data Analytics by Rajni
4,294 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,700 points
77 views
0 votes
2 answers

How to write lines to a text file in R?

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

answered May 24 in Data Analytics by anonymous
1,131 views