Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to plot multiple columns on one plot, using the following code:

df.m <- melt(stkPres, "date")

ggplot(df.m, aes(date, value)) + 
  geom_line() + 
  facet_wrap(~variable, scales = "free")

Which returns a graph like this:

enter image description here

How can I make the plots sized more appropriately?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
273 views
Welcome To Ask or Share your Answers For Others

1 Answer

Here are some options:

  • Don't let scales be free, plot the data on common axes. This will remove the labels between panels.
  • Remove the strip background.
  • Reduce the size and margin of the strip text.
  • Reduce the spacing between panels.

Example below:

library(ggplot2)

ggplot(diamonds, aes(carat, price)) +
  geom_point() +
  facet_wrap(~ interaction(clarity, color)) +
  theme(strip.background = element_blank(),
        strip.text = element_text(size = rel(0.8), margin = margin()),
        panel.spacing = unit(3, "pt"))

Created on 2021-01-20 by the reprex package (v0.3.0)

It seems your x-axis doesn't need to be free if the dates are common. If not having a free y-axis skews your data in weird ways, considering calculating an index instead of the plain data.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...