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

Changing the Appearance of Facet Labels size

I know the question was asked here: Is there a way to increase the height of the strip.text bar in a facet? I want to decrease the height of the strip.text bar without changing the text size. In the current case there is always a space left between…
Alexander
  • 4,527
  • 5
  • 51
  • 98
16
votes
2 answers

Adding a geom_line to all facets in a facet_wrap plot in R

I'm trying to create a facet_wrap plot that compares four separate lines to a common fifth line; the goal is to have this fifth line appearing on all four of the other facet_wrap plots. Here's my minimal code: library(ggplot2) x = c( 1, 3, 1, …
hfisch
  • 1,312
  • 4
  • 19
  • 36
15
votes
1 answer

Setting absolute size of facets in ggplot2

I'm creating several facetted plots for a report. The number of facets varies between 2 and 8. Ideally, I'd like the absolute size of each facet (across plots) to be the same (e.g. 4x4 cm) so that it is easier to compare them (and it looks nicer,…
erc
  • 10,113
  • 11
  • 57
  • 88
14
votes
3 answers

geom_tile and facet_grid/facet_wrap for same height of tiles

Using ggplot, I would like represent a graph tile with panel, but with same height tile for each panel. I have this graph : dataSta <- list(sites=rep(paste("S", 1:31),each=12), month=rep(1:12,31), value=round(runif(31*12, min=0, max=3000)),…
Ma.
  • 245
  • 3
  • 8
13
votes
2 answers

Percentage histogram with facet_wrap

I am trying to combine percentage histogram with facet_wrap, but the percentages are not calculated based on group but all data. I would like each histogram to show distribution in a group, not relative to all population. I know it is possible to do…
AAAA
  • 461
  • 6
  • 22
13
votes
2 answers

ggplot2: Coloring axis text on a faceted plot

A previously asked question tackles the problem of coloring axis text. However, none of the provided solutions work in a faceted setting, specifically when the scales parameter is set to "free". Consider the following dataset: library( ggplot2 ) X…
Artem Sokolov
  • 13,196
  • 4
  • 43
  • 74
12
votes
2 answers

Creating a multiple column facet function

I am trying to create a facet_multi_col() function, similar to the facet_col() function in ggforce - that allows for a facet layout with a space argument (which is not available in facet_wrap()) - but over multiple columns. As in the last plot below…
guyabel
  • 8,014
  • 6
  • 57
  • 86
12
votes
2 answers

How to remove only some facet labels?

Using facet_wrap, is it possible to remove only some facet labels? In the following example I'd like the Species label to only appear in the first column of each row. I know I can use the labeller function but not how to change individual…
erc
  • 10,113
  • 11
  • 57
  • 88
12
votes
1 answer

Is it possible to reorder only the facets of facet_wrap, without reordering the underlying factor levels?

Sample data frame: df <- data.frame(x=rep(1:10,4),y=rnorm(40),Case=rep(c("B","L","BC","R"),each=10)) I can plot each time series in its own facet with: ggplot(df,aes(x=x,y=y,color=Case)) + geom_line()+facet_wrap(~Case,nr=2,nc=2) Now, suppose I…
DeltaIV
  • 4,773
  • 12
  • 39
  • 86
12
votes
2 answers

ggplot2: Changing the order of stacks on a bar graph

I'm trying to make a stacked bar graph with a facet_wrap, but I want the order of my stacked variables ("developed") to be flipped. I've reordered the factors, and tried "order=descend()," as well as "scale_fill_manual" and nothing seems to…
Natalie K
  • 121
  • 1
  • 6
11
votes
3 answers

Rotate Strip Text in ggplot2

I'm having a hard time figuring out how to rotate the strip.text attribute in theme from ggplot2. I'm using R version 3.4.2 and ggplot2 version 2.2.1. Below is the data for the MWE. > dput(dd) structure(list(type = structure(c(1L, 2L, 3L, 4L, 1L,…
sempervent
  • 833
  • 2
  • 11
  • 23
11
votes
4 answers

Expression in ggplot2 facet labels

I would like to have an R expression in a ggplot2 facet label. Let's say I'm plotting the tips data.frame: library(reshape2) > head(tips) total_bill tip sex smoker day time size 1 16.99 1.01 Female No Sun Dinner 2 2 10.34…
user1701545
  • 5,706
  • 14
  • 49
  • 80
10
votes
1 answer

R ggplot facet_wrap with different y-axis labels, one values, one percentages

I'm plotting a time series value with its percentages using facet_wrap in ggplot: For the plot below, the upper plot is the value, and the lower plot is percentage change. And I would like the y-axis in the lower plot to be "%". Normally in ggplot I…
Chenying Gao
  • 310
  • 4
  • 14
10
votes
1 answer

Multiple rows in facet_grid

I have a dataset that looks roughly like this: names = tibble(NAME_2=c("Location1","Location2","Location3","Location4")) dates = tibble(date = seq(as.Date("2015-01-01"), as.Date("2016-12-31"), by="days")) types = tibble(type =…
LukasKawerau
  • 1,071
  • 2
  • 23
  • 42
10
votes
1 answer

ggplot add ticks to each plot in a facet_wrap

I'd like to display x-axis ticks on plots in the upper rows in facet_wraps. For example: library(ggplot2) ggplot(diamonds, aes(carat)) + facet_wrap(~ cut, scales = "fixed") + geom_density() generates this plot: I'd like to have ticks as I've…
conor
  • 1,204
  • 1
  • 18
  • 22
1
2
3
58 59