How to arrange ggplots in custom order?

0 votes
How to arrange ggplot in a custom order? I want to group a few ggplots. Can someone help?
Oct 29 in Data Analytics by ch
• 3,290 points
19 views

1 answer to this question.

0 votes

You can arrange a ggplot by using a grid and arranging them custom using grid.arrange function from gridExtra package.

See the below example.

p1 <- qplot(data=mpg,cyl,displ)
p2 <- qplot(cyl,data=mpg)
#extra blob to show layout of the grid
blank_rect = rectGrob(x = unit(0.5,"npc"),y = unit(0.5,"npc"),width = unit(1,"npc"),height = unit(1,"npc"),gp=gpar(fill="grey"))
#order the pllots by chnagig the order inside grid.arrange function.
grid.arrange(p1,blank_rect,blank_rect,p2,nrow = 2) 
answered Oct 29 by Cherukuri
• 31,840 points

Related Questions In Data Analytics

0 votes
2 answers

How to arrange a data set in ascending order based on a variable?

In your case it'll be, orderedviews = arrange(movie_views, ...READ MORE

answered Nov 27, 2018 in Data Analytics by Kalgi
• 42,330 points
50 views
0 votes
1 answer

How to order bars in a bar graph using ggplot2?

The key to ordering is to set ...READ MORE

answered Jun 1, 2018 in Data Analytics by DataKing99
• 8,130 points
188 views
0 votes
1 answer

How to write a custom function which will replace all the missing values in a vector with the mean of values in R?

Consider this vector: a<-c(1,2,3,NA,4,5,NA,NA) Write the function to impute ...READ MORE

answered Jul 4, 2018 in Data Analytics by CodingByHeart77
• 3,690 points
189 views
0 votes
0 answers

How to add custom labels to charts in R?

How to add custom labels to charts ...READ MORE

Jul 3 in Data Analytics by Prerana
18 views
0 votes
1 answer

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

By Using gridExtra library we can easily ...READ MORE

answered Apr 16, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,721 views
0 votes
1 answer
0 votes
0 answers
0 votes
1 answer

Create a dual axis column/bar chart using ggplot in R

Add position = "stack" in geom_bar() function ...READ MORE

answered Nov 4 in Data Analytics by sindhu
84 views
0 votes
2 answers

How to sort a data frame by columns in R?

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

answered Aug 21 in Data Analytics by anonymous
• 31,840 points
146 views
0 votes
2 answers

How to count the number of elements with the values in a vector?

Use dplyr function group_by(). > n = as.data.frame(num) > ...READ MORE

answered Aug 21 in Data Analytics by anonymous
• 31,840 points
130 views