Questions tagged [facet-wrap]

In R graphics system ggplot2, facet_wrap is a way to wrap a 1d ribbon of panels into 2d shape. Typically, it groups a data set by one or more categorical variables or variables coercible to factor and plots one data group per panel using the same aesthetics mappings.

In R graphics system ggplot2, facet_wrap is a way to wrap a 1d ribbon of panels into 2d shape. Typically, it groups a data set by one or more categorical variables or variables coercible to factor and plots one data group per panel using the same aesthetics mappings.

Resources for using facet_wrap:

873 questions
6
votes
3 answers

How can one control the number of axis ticks within `facet_wrap()`?

I have a figure created with facet_wrap visualizing the estimated density of many groups. Some of the groups have a much smaller variance than others. This leads to the x axis not being readable for some panels. Minimum reproducable…
LuckyPal
  • 345
  • 2
  • 11
6
votes
1 answer

Adding individual lines to facet_wrapped plot

I'm trying to use facet_wrap to plot a bunch of dataset as scatterpoints, each with an individual line in them indicating when a specific event happened. However, I haven't been able to get the lines to show up individually in each plot, but rather…
Austin
  • 103
  • 1
  • 3
6
votes
3 answers

Edit distance between the facet / strip and the plot

For example, library(ggplot2) ggplot(mpg, aes(displ, cty)) + geom_point() + facet_grid(cols = vars(drv)) How can I change the distance between the strip and the main plot? (For example, create a gap between the strip and the main plot.) But I…
Feng Tian
  • 1,559
  • 1
  • 18
  • 27
6
votes
4 answers

Setting the last plot in the middle with facet_wrap

I am trying to create some multiplots with facet_wrap. However I am not sure if is the right approach for my graph. Here is a short reproducible example: ggplot(airquality, aes(x = Day, y = Temp)) + facet_wrap(~Month) + geom_line() This…
Leo96
  • 489
  • 3
  • 12
6
votes
1 answer

Independent strip themes for ggplot2 facet_wrap using more than one variable

Is it possible to have independent strip themes for each variable used in ggplot2 facet_wrap? Take this chunk of code as an example: p1 <- ggplot(mpg, aes(displ, hwy)) + geom_point() + facet_wrap(c("cyl", "drv"), labeller =…
Ricardo A.
  • 156
  • 8
6
votes
3 answers

ggplot: Showing x-axis line for each facet plot

I have created a facet plot using ggplot which has 4 rows and 1 column with this code: ggplot(data=c, aes(x=Time, y=X.mean, fill = Site, width=.1)) + geom_bar(stat="identity", position=position_dodge(), width=0.5,colour="black", …
user2553008
  • 61
  • 1
  • 3
5
votes
1 answer

Center facets in ggplot2

I'm plotting geom_smooths in facets grouped by size: library(ggplot2) ggplot(df, aes(x = pos, y = mean_ratio_f ))+ geom_smooth(aes(group = factor(size)), method = "lm", se = FALSE, linewidth = 0.5) + # facets: facet_wrap(. ~ size,…
Chris Ruehlemann
  • 20,321
  • 4
  • 12
  • 34
5
votes
2 answers

How to control which facet_wrap labels are displayed

In the following use of facet_wrap, both the year and model are displayed in the plot labels. library(tidyverse) mpg %>% filter(manufacturer=='audi')%>% ggplot(aes(cty, hwy)) + geom_point(aes(col = model)) + facet_wrap(year~model) We…
Ryan
  • 1,048
  • 7
  • 14
5
votes
1 answer

Independent color gradient for each facet in facet_wrap() + ggplot2()

I'm struggling to plot a gradient color scale for each facet in facet_wrap() independently. Data is too big to post it here but here is my code: ggplot(stack, aes(hour, day)) + geom_tile(aes(fill = percent), colour = "white") + …
piblo95
  • 123
  • 1
  • 2
  • 10
5
votes
0 answers

Unique y-axis in facet_grid in each single panel (rows AND columns)

I am struggling to give each single pannel in facet_grid its own y-axis. So basically I want all subplots of this plot to have it's own y-axis (so that you can actually see the data). At the same time, I want a fixed x-axis per column as it is…
Svenno Nito
  • 635
  • 1
  • 6
  • 22
5
votes
2 answers

include plot of all data within each facet_wrap

Dataframe (borrowed from here): df.test <- data.frame(id = rep(1:6, each = 50), x = rnorm(50*6, mean = 10, sd = 5), y = rnorm(50*6, mean = 20, sd = 10), z = rnorm(50*6, mean = 30, sd =…
SorenK
  • 155
  • 9
5
votes
2 answers

How to remove the comma in facet labels when ".multi_line = FALSE"

ggplot(mpg, aes(displ, hwy)) + geom_point() + facet_wrap(c("cyl", "drv"), labeller = labeller(.multi_line = FALSE)) I would like to replace the comma with space in labels.
Zuooo
  • 337
  • 2
  • 11
5
votes
3 answers

How to remove NA from facet_wrap in ggplot2?

I am trying to use facet_wrap to make a polygon map in ggplot2. I have two factor levels (soybean, Maize) in my variable "crop" However, I am getting three plots: soybean, maize and one with NA values. In addition NA values are not displayed in the…
albren
  • 109
  • 1
  • 1
  • 8
5
votes
2 answers

How to lengthen specific tick marks in facet gridded ggplot?

I want longer tick marks for those with labels in a facet grid. So I worked through this attempt and tried to adapt it to facet gridded plots like so: Defining breaks and labels, minor and major: range.f <- range(unique(df1$weeks)) minor.f <- 1 #…
jay.sf
  • 60,139
  • 8
  • 53
  • 110
5
votes
1 answer

How to order bars within all facets?

This question is following my (now deleted) question. This is my data : i <- data.frame( nbr =c(15.18 ,11.53 ,13.37 ,9.2, 10.9, 12.23 ,9.53, 9.81, 7.86, 12.79, 22.03 ,17.64 ,18.1, 16.78 ,17.53 ,16.97 ,17.76 ,18.35 ,12.82 ,20.91, 22.09 ,19.18…
Ph.D.Student
  • 704
  • 6
  • 27