0

I hadn't plotted much with R so far, I want to facet the plot with free scales and spaces. What I tried so far is

ggplot(df3, aes(x = Scores, y = Value)) +
  geom_bar( aes(fill=Input),
            stat = "identity", position = position_dodge()
  ) + scale_fill_manual(values = c("#EFC000FF","#868686FF", "#0073C2FF", "#CD534CFF"))+ theme_pubr() +
facet_grid(. ~ Group, scales = "free", space = "free_x") 

enter image description here

So I cant get the free y scales. This is probably trivial, but I didn't find anything that compares.

3
  • Hi Qwap! Welcome to StackOverflow. Could you please edit your question to make it a reproducible one? Thanks a bunch ! Commented Jul 9, 2023 at 8:27
  • 1
    stackoverflow.com/questions/5963269/… Commented Jul 9, 2023 at 8:27
  • 2
    Does this answer your question? ggplot2, facet_grid, free scales? Commented Jul 9, 2023 at 8:40

1 Answer 1

3

You cannot get free "y" scales by facet_grid() for each row, but if you insisted on it, you could try using facet_grid2() from {ggh4x} package.

For example:

# install.packages("ggh4x")
ggplot(df3, aes(x = Scores, y = Value)) +
  geom_bar( aes(fill=Input),
            stat = "identity", position = position_dodge()
  ) + 
  scale_fill_manual(values = c("#EFC000FF","#868686FF", "#0073C2FF", "#CD534CFF")) + 
  theme_pubr() +
  ggh4x::facet_grid2(. ~ Group, independent = "y", scales = "free", space = "free_x") 

See this manual for more information.

Sign up to request clarification or add additional context in comments.

1 Comment

You are welcome! We should say thanks to the author of ggh4x, too. :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.