【问题标题】:three graphs that share an axis共享一个轴的三个图
【发布时间】:2015-12-11 18:17:35
【问题描述】:

我需要制作一个由共享相同 X 轴但具有不同 Y 轴的三个图组成的图。这是否可以在 R 中完成,或者我是否需要制作三个独立的图表并将它们放在像 Adob​​e Illustrator 这样的程序中?

【问题讨论】:

  • 在提出绘图问题时,将reproducible example 包含在我们可以测试的样本输入数据中会很有帮助。如果我们必须创建测试数据来测试可能的解决方案,就很难为您提供帮助。
  • ggplot2facet_grid的文档
  • 我同意@MrFlick 的观点,但插图足以说明问题,可以轻松推断出 OP 的目标。

标签: r graph shared axes


【解决方案1】:

使用ggplot2

library(ggplot2)

ggplot(mtcars, aes(x = wt, y = mpg)) + 
  geom_point() + 
  facet_grid(cyl ~ ., scales = "free_y") + 
  theme_bw()

【讨论】:

    【解决方案2】:

    使用基础包中的绘图,您可以使用 标准杆命令。不仅仅是在关闭前 2 个轴时添加图表。我建议阅读绘图和图形文档,了解可以调整哪些内容以使绘图看起来不错。

    #############
    # Data 
      x<-1:10
      y<- 1+ x*1.2
    #############
    par(mfrow=c(3,1)) # allow 3 graphs in the plot window 3 rows, 1 column
    # plot 1
    plot(x,y, axes=F, xlab=NA, ylab=NA)   
    box()
    axis(2,seq(min(y), max(y),1), las=2)
    # plot 2
    plot(x,y, axes=F, xlab=NA, ylab="Y")  
    box()
    axis(2,seq(min(y), max(y),1), las=2)
    # plot 3
    plot(x,y, axes=T, xlab="X", ylab=NA)  
    box()
    axis(2,seq(min(y), max(y),1), las=2)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-10-14
      • 2021-12-15
      • 2018-01-04
      • 1970-01-01
      • 2023-02-14
      • 2021-04-24
      • 1970-01-01
      相关资源
      最近更新 更多