为R中的对齐图创建伞形标题 [英] Creating umbrella titles for aligned graphs in R

查看:96
本文介绍了为R中的对齐图创建伞形标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have succeeded in creating and aligning three scatter-plots in R, using the following code:

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轴使用单个Axis标签来节省空间.我已经尝试过使用par()函数进行实验,插入x和ylab函数,但是由于这些不是图形参数,因此似乎无法接受它们.我怀疑问题出在我将这些信息放在代码中的位置,因为使用xlab和ylab似乎很有意义,并且我可以在各个绘图代码中编写x和ylab =".

What I would like to do now is save space by having a single Axis label for the x and y axis. I have tried experimenting with the par() function, inserting x and ylab functions, but it seems that as these are not graphical parameters is will not accept them. I suspect the problem lies in where I place this information in the code, as using the xlab and ylab seems to make sense, and I can write x and ylab = "" in the individual plot codes.

我也在努力更改主标题的位置,以使标题出现在左侧,从x轴删除值,以便它们仅显示在整个图形的底部,并排列图形这样就可以减少空间.

I am also struggling to change the position of the main titles so that the appear on the left, to remove the values from the x-axis so that they only show at the bottom of the whole figure, and to arrange the figure so that there is less space.

此图显示了当前布局以及我要实现的布局:

This figure shows the current layout and the layout I want to achieve:

很抱歉一次发表这么多问题.我对R还是很陌生,尽管我到达那里,但是编程仍然会发现帮助文件有些令人生畏.关于功能,将其放置在何处以及如何使用它们以实现其中一些目标的一些建议将是不错的.

I am sorry to post so many questions at once. I am very new to R and programming am still finding the helpfiles a bit daunting, although I am getting there. Some suggestions on functions, where to put them and how to use them to achieve some of these aims would be great.

推荐答案

此答案基于hrbrmstr的答案,但结果更接近于所请求的布局:

This answer is based on hrbrmstr's answer, but the result is closer to the requested layout:

# 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)

这篇关于为R中的对齐图创建伞形标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆