Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

How to vary x-axis scales by column in facet_wrap and ggplot2

$
0
0

I am creating a 2x2 ggplot using facet_wrap where the columns are two different groups.This means that the x-axis on the columns is the same between the top row and the bottom row, but different between the columns. I want to remove the repeated x-axis tick labels, when they are repeated.

Is it possible to have the x-axis vary between columns in facet_wrap?

This is a toy example of the data, and what I have tried so far. What you will see is that the x-axis is repeated in the top and bottom row, when I use the argument "scales = free_x". If I don't use free_x then the scale of the x-axis is too wide for each plot.

Is there an argument I could use, or should I be looking at something like patchwork to link the plots together?

library(ggplot2)n = 100df = data.frame(x = c(rnorm(n/2), rnorm(n/2, mean = 100)),                y = rnorm(n),                group = rep(1:2, each = n/2),                facet = rep(c("A", "C", "B", "D"), each = n/4))ggplot(data = df, aes(x = x, y = y)) +  geom_point() +  facet_wrap(~facet + group, scales = "free_x")

Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>