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
10
votes
2 answers

Showing multiple axis labels using ggplot2 with facet_wrap in R

I've got a nice facet_wrap density plot that I have created with ggplot2. I would like for each panel to have x and y axis labels instead of only having the y axis labels along the left side and the x labels along the bottom. What I have right now…
JD Long
  • 59,675
  • 58
  • 202
  • 294
9
votes
2 answers

Long facet_wrap labels in ggplotly / plotly overlap facet's strip.background

I've got a plot like the one below, where I need to display a plot title and some long facet labels. In ggplot2, it looks just fine. Reprex: library(ggplot2) library(stringr) library(plotly) iris$Species2 <- paste(iris$Species, "... some text to…
Nova
  • 5,423
  • 2
  • 42
  • 62
9
votes
2 answers

R ggplot - adding all data points to all facets

until now I can't find an appropriate answer, here is my short question about ggplot2 in R: data(mtcars) ggplot(data=mtcars, aes(x=mpg, y=wt, fill=factor(cyl))) + scale_fill_manual(values=c("red","orange","blue"))+ geom_point(size=2,…
mod_che
  • 137
  • 1
  • 6
9
votes
1 answer

ggplot2, facet wrap, fixed y scale for each row, free scale between rows

I would like to produce a plot using facet_wrap that has a different y scale for each row of the wrap. In other words, with fixed scales on the same row, free scales on different rows, with a fixed x scale. Free scales doesn't give me exactly what…
kmccoy
  • 93
  • 1
  • 4
9
votes
2 answers

R/ggplot: Vertical strip text with facet_wrap

I'm using ggplot in R to plot several conditions with facet_wrap. I'd like to put the strip with the plot name on the vertical axis on the right instead of on top. This is an example: library(ggplot2) dat<- data.frame(name= rep(LETTERS[1:5], each=…
dariober
  • 8,240
  • 3
  • 30
  • 47
8
votes
2 answers

Plotting means on histograms created with facet_wrap

I'm making a several histograms using ggplot2 and facet_wrap and would like to plot the mean value on each panel. Below, I create a dummy data frame, find the mean of each facet, and then create the plots adding the mean using geom_point. # Load…
Dan
  • 11,370
  • 4
  • 43
  • 68
8
votes
2 answers

Facet_Wrap labels in R

I'm trying to change labels for ggplot graph with facets, and am using a variable from the dataframe which is not faceted. The code is as belows- iris %>% group_by(Species) %>% summarise(lbl = mean(Petal.Length)) %>% select(lbl) %>% unlist()…
Mridul Garg
  • 477
  • 1
  • 8
  • 17
8
votes
1 answer

Starting Y axis at 0 using ggplot and facet_wrap

I'm using the following code: x_breaks <- seq(as.Date("2010/1/1"), as.Date("2015/4/1"), "months") x_labels <- as.character(x_breaks, format="%b%y") thousand_formatter<-function(x){ return(as.integer(x)) } vLines <-…
Patthebug
  • 4,647
  • 11
  • 50
  • 91
8
votes
1 answer

set x/y limits in facet_wrap with scales = 'free'

I've seen similar questions asked, and this discussion about adding functionality to ggplot Setting x/y lim in facet_grid . In my research I often want to produce several panels plots, say for different simulation trials, where the axes limits…
dan
  • 176
  • 1
  • 7
8
votes
2 answers

How to change the facet labels in facet_wrap

I am using ggplot and facet_wrap to get the required plots. I have to add few things to the labels of each facet or the variable or the name of each facet, just like how we modify the xlab and ylab directly under ggplot. Example: d <-…
cppiscute
  • 707
  • 2
  • 10
  • 33
7
votes
1 answer

ggplot2 facet_grid with facet titles

Is there a canonical way to add facet titles within facet_grid? Or a way to specific row labels in facet_wrap? (Without geom_text, geom_label, or grob manipulation.) Consider: dat <- data.frame(rowInd = paste0("R", c(1, 2, 2, 3, 3, 3)), colInd =…
r2evans
  • 141,215
  • 6
  • 77
  • 149
7
votes
1 answer

labeller not applying labels with facet_wrap and returns NA

I'm trying to use the labeller function within ggplot2 to label faceted plots. When I run my code I don't get any errors or warnings (which I know doesn't always mean everything is working like I think it is), but instead of my predefined labels…
Curtis
  • 449
  • 1
  • 4
  • 17
7
votes
1 answer

ggplot2 facet_wrap: only use x-axis labels existing in each group

I have the following dataset: subj <- c(rep(11,3),rep(12,3),rep(14,3),rep(15,3),rep(17,3),rep(18,3),rep(20,3)) group <- c(rep("u",3),rep("t",6),rep("u",6),rep("t",6)) time <- rep(1:3,7) mean <- c(0.7352941, 0.8059701, 0.8823529, 0.9264706,…
absurd
  • 1,035
  • 3
  • 14
  • 35
7
votes
1 answer

how to add two regression line equations and R2s with each facet?

I would like to add two regression line equations and R2s with each facet. I adopted Jayden's function to solve the problem, but I found that each equation was the same. The likely reason is sending wrong subset of data to the function. Any advice…
just_rookie
  • 873
  • 12
  • 33
7
votes
0 answers

How to change ylim per facet with coord_cartesian in ggplot?

This answer describes how to change the y limits of a plot in ggplot. Suppose I have a faceted plot with a different ylim for each facet, e.g. facet_wrap(~some_facet, scales="free_y") How can I change the y limits for each facet differently?
dfrankow
  • 20,191
  • 41
  • 152
  • 214
1 2
3
58 59