Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 为ggplot中的每个面设置不同的Y轴限制_R_Ggplot2 - Fatal编程技术网

R 为ggplot中的每个面设置不同的Y轴限制

R 为ggplot中的每个面设置不同的Y轴限制,r,ggplot2,R,Ggplot2,我需要修改我的代码,为所附图片中的每个图表设置不同的Y轴限制。 我希望顶部的第一个和第二个图表的Y轴限制在-4到-22之间,第三个图表的Y轴限制在-4到8之间,第四个图表的Y轴限制在0到90之间,底部图表的Y轴限制在0到1之间 myChart <- ggplot() + geom_line(data=fileInMeltSub, aes(x=DOY, y=value, color=ROI), size=1.4) + geom_point(data=fileInMeltSub, a

我需要修改我的代码,为所附图片中的每个图表设置不同的Y轴限制。 我希望顶部的第一个和第二个图表的Y轴限制在-4到-22之间,第三个图表的Y轴限制在-4到8之间,第四个图表的Y轴限制在0到90之间,底部图表的Y轴限制在0到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) 

myChart我决定使用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)

dB_HH我决定使用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)

dB_HH看。可能是No的重复,我已经看到了,但它对我没有帮助。我有5个面,我必须设置4个不同的Y轴限制。也许最好的方法是学习如何使用grid.arrange您需要使用与您的
文件inmeltsb
中相同的刻面变量制作一个
dummy
data.frame,正如我链接到的问题中所述。请参阅。可能重复的不是,我已经看到了,但这对我没有帮助。我有5个面,我必须设置4个不同的Y轴限制。也许最好的方法是学习如何使用grid.arrange您需要使用与您的
文件inmeltsub
中相同的刻面变量制作一个
虚拟
data.frame,完全如我链接的问题中所述。