【问题标题】:Creating umbrella titles for aligned graphs in R在 R 中为对齐图创建伞形标题
【发布时间】:2015-11-06 11:22:51
【问题描述】:

我已使用以下代码成功地在 R 中创建并对齐了三个散点图:

par(mfrow = c(3,1))

plot(CGP.GOSL ~ FPT.MAF.GOSL, data = all.locs, main = "A. Place I")
  abline(h=c(0.5))
  abline(v=c(0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5), lty=2)
plot(CGP.IRE ~ FPT.MAF.IRE, data = all.locs, main = "B. Place II")
  abline(h=c(0.5))
  abline(v=c(0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5), lty=2)
plot(CGP.BAR ~ FPT.MAF.BAR, data = all.locs, main = "C. Place III")
  abline(h=c(0.5))
  abline(v=c(0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5), lty=2)

我现在想做的是通过为 x 和 y 轴设置一个轴标签来节省空间。我尝试过使用 par() 函数,插入 x 和 ylab 函数,但似乎因为这些不是图形参数,所以不会接受它们。我怀疑问题在于我将这些信息放在代码中的位置,因为使用 xlab 和 ylab 似乎很有意义,我可以在单独的绘图代码中编写 x 和 ylab = "" 。

我也在努力改变主要标题的位置,以便出现在左侧,从 x 轴上删除值,以便它们只显示在整个图的底部,并排列图这样空间就小了。

这个图展示了当前的布局和我想要实现的布局:

很抱歉一次发布这么多问题。我对 R 非常陌生,编程仍然发现帮助文件有点令人生畏,尽管我已经到了那里。关于功能的一些建议,将它们放在哪里以及如何使用它们来实现其中一些目标会很棒。

【问题讨论】:

  • 请在下面找到之前和之后图像的链接,以获得一些所需的效果并帮助可视化。 Stackoverflow 不允许我以新用户身份上传图片。之前:tinyurl.com/qcffovm 之后:tinyurl.com/oktbsfz
  • 第二个 URL 似乎没有图像(我为第一个添加了图形)

标签: r graphics scatter-plot


【解决方案1】:

文档有时会有点挑战性。这是我认为您正在寻找的骨架:

# 3 rows
par(mfrow=c(3,1))

# tighter margins
par(mar = c(0, 0, 0, 0), oma = c(4, 4, 0.5, 0.5))

# need some data
data(cars)

# 3 plots, no axis junk
plot(cars, ann=FALSE)
plot(cars, ann=FALSE)
plot(cars, ann=FALSE)

# outer labels
mtext("x axis", side = 1, outer = TRUE, cex = 0.7, line = 2.2)
mtext("y axis", side = 2, outer = TRUE, cex = 0.7, line = 2.2)

【讨论】:

    【解决方案2】:

    这个答案是基于 hrbrmstr 的答案,但结果更接近请求的布局:

    # 3 rows
    par(mfrow=c(3,1))
    
    # Adjust margins. Each vector element refers to one side of the plot; 
    # the order is c(bottom, left, top, right). (See ?par)
    par(mar = c(2.5, 4.1, 1, 2.1), oma = c(3, 3, 2, 0))
    
    # need some data
    data(cars)
    
    
    # 3 plots. On the first two: Suppress axis labels (ann = FALSE) and 
    # the x axis (xaxt = "n"), then add the ticks using axis() and the
    #  title using mtext(). On the last one, do not suppress x axis.
    # Note that repeating arguments could be set globally using par().
    
    plot(cars,  ann = FALSE, xaxt = "n")
    axis(side = 1, labels = FALSE)
    mtext(text = "A. Place I", side = 3, at = par("usr")[1], line = 1)
    
    plot(cars, ann=FALSE, xaxt = "n")
    axis(side = 1, labels = FALSE)
    mtext(text = "B. Place II", side = 3, at = par("usr")[1], line = 1)
    
    plot(cars, ann=FALSE)
    mtext(text = "C. Place III", side = 3, at = par("usr")[1], line = 1)
    
    # outer labels
    mtext("X Axis label", side = 1, outer = TRUE)
    mtext("Y Axis label", side = 2, outer = TRUE)
    

    【讨论】:

      猜你喜欢
      • 2020-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-13
      • 1970-01-01
      • 2019-06-07
      • 1970-01-01
      相关资源
      最近更新 更多