1

enter image description hereI need to modify my code to set different Y axis limits for each chart in the picture attached. I would like that the first and second charts from the top have Y axis limits from -4 to -22, the third needs to have Y limits from -4 to 8, the forth from 0 to 90 and the bottom charts from 0 to 1.

myChart <- ggplot() +

  geom_line(data=fileInMeltSub, aes(x=DOY, y=value, color=ROI), size=1.4) +
  geom_point(data=fileInMeltSub, aes(x=DOY, y=value, color=ROI), size=2.2) +

  # facet
  facet_wrap(~ variable, ncol=1, scales = "free_y") +[![enter image description here][1]][1]

  # start X11
  x11(width = 50, height = 50)
  plot(myChart) 
ilFonta
  • 241
  • 2
  • 15
  • See https://stackoverflow.com/questions/18046051/setting-individual-axis-limits-with-facet-wrap-and-scales-free-in-ggplot2. – echasnovski Nov 04 '17 at 21:31
  • 3
    Possible duplicate of [Setting individual axis limits with facet\_wrap and scales = "free" in ggplot2](https://stackoverflow.com/questions/18046051/setting-individual-axis-limits-with-facet-wrap-and-scales-free-in-ggplot2) – Curt F. Nov 05 '17 at 06:15
  • No, I already seen that, but it doesn't help me. I have 5 facets and I have to set 4 different Y axis limits. Maybe the best is to learn how to use grid.arrange – ilFonta Nov 05 '17 at 09:51
  • You need to make a `dummy` data.frame with the same faceting variable(s) as in your `fileInMeltSub`, exactly as described in the question I linked to. – Curt F. Nov 05 '17 at 16:22

1 Answers1

0

I decided to solve my issue using the gridExtra library, because it permits a very high flexibility. Here is the code

dB_HH <- subset(fileInMelt, variable == "mean_HH_dB")
dB_VV <- subset(fileInMelt, variable == "mean_VV_dB")
dB_HH.VV <- subset(fileInMelt, variable == "mean_HH.VV_dB")
dB_alpha <- subset(fileInMelt, variable == "mean_alpha")
dB_entropy <- subset(fileInMelt, variable == "mean_entropy")

# -----------------------------------------------------------------------------------------------------------------------
# charts

myChartHH <- ggplot(data=dB_HH, aes(x=DOY, y=value, color=ROI)) +
  geom_line(size=1.4) +
  geom_point(size=2.2) +
  guides(color=guide_legend(title=NULL)) +
  labs(y = "HH") +
  labs(x = "") +
  scale_y_continuous(limits = c(-24,-4)) +
  theme(legend.position="none")

  # x11(width = 50, height = 50)
  # plot(myChartHH)

  # ---------------------------------------------------------------

myChartVV <- ggplot(data=dB_VV, aes(x=DOY, y=value, color=ROI)) +
  geom_line(size=1.4) +
  geom_point(size=2.2) +
  guides(color=guide_legend(title=NULL)) +
  labs(y = "VV") +
  labs(x = "") +
  scale_y_continuous(limits = c(-24,-4)) +
  theme(legend.position="none")  

  # x11(width = 50, height = 50)
  # plot(myChartVV)

  # ---------------------------------------------------------------

myChartHHVV <- ggplot(data=dB_HH.VV, aes(x=DOY, y=value, color=ROI)) +
  geom_line(size=1.4) +
  geom_point(size=2.2) +
  guides(color=guide_legend(title=NULL)) +
  labs(y = "HH/VV") +
  labs(x = "") +
  scale_y_continuous(limits = c(-4,8)) +
  theme(legend.position="none")

  # x11(width = 50, height = 50)
  # plot(myChartHHVV)

  # ---------------------------------------------------------------

myChartAlpha <- ggplot(data=dB_alpha, aes(x=DOY, y=value, color=ROI)) +
  geom_line(size=1.4) +
  geom_point(size=2.2) +
  guides(color=guide_legend(title=NULL)) +
  labs(y = "alpha") +
  labs(x = "") +
  scale_y_continuous(limits = c(0,90)) +
  theme(legend.position="none")

  # x11(width = 50, height = 50)
  # plot(myChartAlpha)

  # ---------------------------------------------------------------

myChartEntropy <- ggplot(data=dB_entropy, aes(x=DOY, y=value, color=ROI)) +
  geom_line(size=1.4) +
  geom_point(size=2.2) +
  guides(color=guide_legend(title=NULL)) +
  labs(y = "entropy") +
  labs(x = "DOY") +
  scale_y_continuous(limits = c(0,1)) +
  theme(legend.position="none")

  # x11(width = 50, height = 50)
  # plot(myChartEntropy)

  # ---------------------------------------------------------------

totChart <- grid.arrange(myChartHH, 
             myChartVV, 
             myChartHHVV,
             myChartAlpha,
             myChartEntropy,
             ncol=1)

x11(width = 50, height = 50)
plot(totChart)
ilFonta
  • 241
  • 2
  • 15