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
5
votes
1 answer

ggplot2 - include one level of a factor in all facets

I have some time series data that is facet wrapped by a variable 'treatment'. One of the levels of this 'treatment' factor the a negative control & I want to include it in every facet. For example using R dataset…
Cam
  • 87
  • 5
5
votes
0 answers

ggplot2 facet_wrap Error: predicate must be a closure

Loaded this up in a new R session. I can't figure out what's wrong. library(ggplot2) ggplot(mtcars, aes(mpg, wt)) + geom_point() + facet_wrap( ~ cyl) Error: Error: `predicate` must be a closure or function pointer ls() character(0) Session…
5
votes
0 answers

GGPLOT boxplot: independently specify facet scales

I have plenty of measurements (N ~ 500.000) of two laboratory tests that I wanted to plot using geom_boxplot. These measurements were created using three different analyzers. However, many of these measurements are extreme outliers which leads to…
s.erhardt
  • 77
  • 1
  • 3
  • 9
5
votes
1 answer

How to create a facetted plot with title and subtitle specific to each facet?

Generating a plot combined with separate plots for each column with title and subtitles, along with a vertical line for each plot: I have created using the histogram plot for a column with a vertical…
Prradep
  • 5,506
  • 5
  • 43
  • 84
5
votes
3 answers

ggplot2: specifying different scales for rows in facet layout for bar plots

My data are visualized in the package ggplot2 via bar plots with several (~10) facets. I want first to split these facets in several rows. I can use function facet_grid() or facet_wrap() for this. In the minimal example data here I build 8 facets in…
astrsk
  • 375
  • 6
  • 20
5
votes
2 answers

facet_wrap for histogram in a loop: "At least one layer must contain all variables"

I am looking at producing a faceted histogram in a loop. The problem occurs when I am calling the facet_wrap within the loop. I tried different options but all of them failed with the following message: Error in layout_base(data, vars, drop = drop)…
user3148607
  • 191
  • 11
5
votes
1 answer

Interpretation and plotting of logistic regression

I'm currently working on a research involving different species of bats and fragmentation of the habitat. My dataset contains presence data (1 = present, 0 = absent) and data on the fragment sizes, body mass (both continuous) and feeding guilds…
Y. Hidskes
  • 53
  • 4
5
votes
1 answer

ggplot2: How can I set axis breaks separately for each facet in facet_wrap?

I would like to modify the breaks and limits of y-axis of each one of the graphs in the facet_wrap. I want for example reduce the breaks for some of them or I want that they start from 0. ggplot(granuControlLw, aes(distance, group=time)) +…
gashin
  • 71
  • 1
  • 4
5
votes
1 answer

Add labels to each subplots created using facet_wrap (ggplot2)

I am quite new to ggplot2 (and R) so bear with me. Using facet_wrap, I have created a multi-panel plot. I want to label them with alphabetical letters (starting with the top-left panel labelled with (A), and the next panel with (b) and so on.) but I…
Joshlhj
  • 67
  • 1
  • 6
5
votes
1 answer

Adding mean value to facets

I have this plot, which calculates an index of abbundance of a bird species for a given winter: This graphic comes from this code (themes and scales excluded): ggplot (a, aes (pentada,ika,colour=inv,group=inv,na.rm=T)) +…
Miguel
  • 67
  • 2
  • 9
5
votes
2 answers

ggplot2: multiple plots with box and labels around them

I am trying to create a grid of plots, which should have a box around them, a chessboard-like labelling (i.e., letters at top/bottom, numbers at the sides), as well as a vertical line separating two halfs of the grid. I was hoping to get it done…
simoncolumbus
  • 526
  • 1
  • 8
  • 23
5
votes
1 answer

Customize the background color of facets in ggplot2

Let's say I want to plot my data: my.df = data.frame(mean =…
user1701545
  • 5,706
  • 14
  • 49
  • 80
5
votes
1 answer

Flip facet label and x axis with ggplot2

I am looking to flip the labels on a faceted panel of 1 row and 5 columns, so that the facet headers appear on bottom, and the x axis appears on top of facets. The reason is that I want to reuse those headers for a table that will be directly below…
wesmantooth
  • 625
  • 2
  • 11
  • 29
5
votes
2 answers

ggplot facet_wrap: At least one layer must contain all variables used for facetting

I am using the command qplot(factor(ww), WeeklyYield, geom = "bar", fill = I("grey50"))+facet_wrap(~model+name) to create a bar chart for every combination of model and name. However I get the following error message: Error in layout_base(data,…
user2145299
  • 81
  • 2
  • 3
  • 8
4
votes
1 answer

Error with ggplot facet_wrap: Error: `scale_id` must not be `NA`

I've been stuck on this all morning, but cannot figure it out. Each row of my data comprises: timestamps, measurement, user. If I plot my data as a whole, it works fine. But if I try to plot the data by date using facet_wrap, it keeps failing with…
sparco1500
  • 187
  • 3
  • 15