2017-11-04 12 views
1

enter image description here添付されている画像の各チャートのY軸の制限を異なるように変更する必要があります。 上から1番目と2番目のグラフのY軸の制限は-4〜-22、3番目の制限は-4〜8、前に0〜90、下のグラフには0〜 1.ggplotの各ファセットに異なるY軸の制限を設定する

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) 
+0

がhttps://stackoverflow.com/questions/18046051/setting-individual-axis-limits-with-facet-wrap-and-scales-free-in-ggplot2を参照してくださいコードです。 – echasnovski

+3

[ggplot2]でファセット\ _ラップとスケール\ "フリー\"で個々の軸の限界を設定することができます(https://stackoverflow.com/questions/18046051/setting-individual-axis-limits-with-facet-wrap-and) -scales-free-in-ggplot2) –

+0

いいえ、私はすでにそれを見ましたが、それは私を助けません。私は5つのファセットを持っており、私は4つの異なるY軸の限界を設定しなければなりません。多分grid.arrangeの使い方を学ぶことが最善の方法でしょう。 – ilFonta

答えて

0

非常に柔軟性が高いので、gridExtraライブラリを使用して問題を解決することにしました。ここで

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) 
関連する問題