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
220
votes
6 answers

Annotating text on individual facet in ggplot2

I want to annotate some text on last facet of the plot with the following code: library(ggplot2) p <- ggplot(mtcars, aes(mpg, wt)) + geom_point() p <- p + facet_grid(. ~ cyl) p <- p + annotate("text", label = "Test", size = 4, x = 15, y =…
MYaseen208
  • 22,666
  • 37
  • 165
  • 309
91
votes
4 answers

What's the difference between facet_wrap() and facet_grid() in ggplot2?

I've been reading the ggplot2 documentation for both functions. I was wondering what were the differences and what would be right situation for using each function (facet_wrap() and facet_grid()). library(ggplot2) p <- qplot(displ, hwy, data =…
marbel
  • 7,560
  • 6
  • 49
  • 68
77
votes
5 answers

ggplot2: facet_wrap strip color based on variable in data set

Is there a way to fill the strips of facets created with facet_wrap based on a variable supplied with the data frame? Example data: MYdata <- data.frame(fruit = rep(c("apple", "orange", "plum", "banana", "pear", "grape")), farm =…
Dalmuti71
  • 1,509
  • 3
  • 15
  • 19
44
votes
6 answers

Add x and y axis to all facet_wrap

It is often desirable to minimize ink in a plot. I have a faceted plot (facet_wrap) and would like to remove as much ink as possible yet maintain readability. I have set it up as I'd like except the x and y axis is not present for the facets…
Tyler Rinker
  • 108,132
  • 65
  • 322
  • 519
44
votes
1 answer

add "floating" axis labels in facet_wrap plot

I have the same problem as this user - I have a 'jagged' faceted plot, in which the bottom row has fewer panels than the other rows, and I would like to have x-axis ticks on the bottom of each column. The suggested solution for that problem was to…
Drew Steen
  • 16,045
  • 12
  • 62
  • 90
35
votes
1 answer

Change plot title sizes in a facet_wrap multiplot

Can any help me change the title text size for these plots. i.e. make them larger? Script ggplot(NMPSCMOR, aes(Length, fill=Year)) + geom_histogram(position="dodge", binwidth=60, colour="black") + xlim(0, 600) + scale_fill_grey(start = 1,…
George
  • 1,343
  • 2
  • 12
  • 17
34
votes
1 answer

Scales = "free" works for facet_wrap but doesn't for facet_grid

I'm trying to understand why the outputs of facet_grid() and facet_wrap() are different, even though the inputs are the same: facet_grid ggplot(temp, aes(x = valor)) + geom_histogram(binwidth = 5, fill = NA, color = "black")…
iatowks
  • 970
  • 2
  • 9
  • 21
34
votes
5 answers

Place a legend for each facet_wrap grid in ggplot2

I have this data frame: x <- data.frame( Date = factor(rep( c("12/1/2011", "1/2/2012", "2/1/2012", "2/10/2012", "2/13/2012"), 3 )), Server = factor(rep(c("A", "B", "C"), each = 5L)), FileSystem = factor(c( "/", "/var", "tmp",…
user1471980
  • 10,127
  • 48
  • 136
  • 235
30
votes
3 answers

How to produce different geom_vline in different facets in R?

I am trying to produce 2 different geom_vlines with different colours in 2 different facets of a dataset. I am doing this to highlight means of 2 different facets. Here's the dataset: Pclass Sex Age SibSp Parch Fare Cabin Embarked …
Scott Grammilo
  • 1,229
  • 4
  • 16
  • 37
25
votes
4 answers

ggplot2: Splitting facet/strip text into two lines

Consider the following ggplot2 graph with long facet/strip text broken in two lines. The text goes outside the area devoted to facet titles. library(ggplot2) x <- c(1:3, 1:3) y <- c(3:1, 1:3) grp <- c(0, 0, 0, 1, 1, 1) p <- qplot(x=x, y=y) +…
Marco Sandri
  • 23,289
  • 7
  • 54
  • 58
25
votes
6 answers

multiple column/row facet wrap in altair

In ggplot2, it's easy to create a faceted plot with facets that span both rows and columns. Is there a "slick" way to do this in altair? facet documentation It's possible to have facets plot in a single column, import altair as alt from…
saladi
  • 3,103
  • 6
  • 36
  • 61
22
votes
2 answers

facet_wrap add geom_hline

I have the following code for my ggplot - the facet_wrap function draws out 20 plots on the page for each Name and there are 5 Pcode along the x-axis. I would like to calculate the average TE.Contr for each Name and plot that value as a horizontal…
user8491385
  • 413
  • 1
  • 5
  • 17
22
votes
3 answers

ggplot2: Put multi-variable facet_wrap labels on one line

I am using facet_wrap to split my scatter plot as facet_wrap(x~y+z) This generates 22 plots in my case as desired. However, label for each of those 22 plots is displayed in 3 rows (x, y and z) which unnecessarily consumes the space in the window…
beeprogrammer
  • 581
  • 1
  • 7
  • 18
19
votes
2 answers

ggplot renaming facet labels in facet_wrap

I've hit a stumbling block in writing a ggplot function. I'm trying to change the facet labels in a ggplot facet_wrap plot.... but its proving trickier than I though it would be.... The data I am using can be accessed here str(ggdata) 'data.frame': …
Rory Shaw
  • 811
  • 2
  • 9
  • 26
18
votes
1 answer

Segment facet_wrap into multi-page PDF

I have searched around for a solution to this, but it appears that most deal with individually generated plots being combined into PDF format, rather than separating out plots generated using faceting onto separate pages of a PDF. Example Data In…
ZTIrwin42
  • 195
  • 1
  • 6
1
2 3
58 59