【问题标题】:Create 1 plot from 4 different plots by face_grid in R通过 R 中的 face_grid 从 4 个不同的地块创建 1 个地块
【发布时间】:2020-11-17 15:54:38
【问题描述】:

我有以下数据框: dataframe

我想将两个不同的数据集相互绘制,所以'total_USGS' vs 'total_WRI' 'desalination_USGS' vs 'desalination_WRI' 等等。

我设法在独立的情节中做到这一点,但现在我想通过使用 facet_wrap 的 facet_grid 将它们一起绘制,我搜索了整个互联网,但找不到类似的例子。

有可能吗?

希望收到你们的来信。

【问题讨论】:

  • 嗨Roelalex。没有人回答您的最后一个问题,因为您没有提供数据样本。您的数据截图是没有用的,因为我们无法复制和粘贴数据来测试可能的解决方案。请编辑您的问题以包含一些实际数据,而不是再次发布相同的问题。尝试在控制台中输入 dput(my_dataframe) 并将结果粘贴到您的问题中。除非你这样做,否则真的无法帮助你。
  • 感谢您的回复,我会的!在上一个问题的帮助下,我已经解决了这个问题!

标签: r ggplot2 facet-wrap facet-grid


【解决方案1】:

您可以想办法绘制这些图表。由于您没有提供可重现的代码,我通常会向您解释您可以做什么。 将两张图保存在两个单独的变量中:

a <- graph code for 'total_USGS' vs 'total_WRI' 
b <- graph code for 'desalination_USGS' vs 'desalination_WRI'

然后您可以使用网格排列将图组合在一起。

library(gridExtra)
grid.arrange(a, b) 

【讨论】:

    【解决方案2】:

    所以首先我创建了 4 个不同的图表:

    totalComparison= ggplot(stateSum) + geom_point(aes(x=total_USGS, y=total_WRI)) + geom_abline(slope=1, intercept=0, color='red') totalComparison

    desalinationComparison= ggplot(stateSum) + geom_point(aes(x=desalination_USGS, y=desalination_WRI)) + geom_abline(slope=1, intercept=0, color='red') desalinationComparison

    surfacewaterComparison= ggplot(stateSum) + geom_point(aes(x=surfacewater_USGS, y=surfacewater_WRI)) + geom_abline(slope=1, intercept=0, color='red') surfacewaterComparison

    groundwaterComparison= ggplot(stateSum) + geom_point(aes(x=groundwater_USGS, y=groundwater_WRI)) + geom_abline(slope=1, intercept=0, color='red') groundwaterComparison

    然后我使用 grid.arrange 创建了一种 facet wrap:

    totalGrid= grid.arrange(totalComparison, desalinationComparison, surfacewaterComparison, groundwaterComparison, ncol=2, nrow=2)

    然后给出这个:

    【讨论】:

      猜你喜欢
      • 2020-05-18
      • 2012-09-16
      • 2021-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多