简体   繁体   中英

Move title of plots in a list of plots in R

I have a list of plots that I have assigned names to, and then converted to plot titles as suggested by https://stackoverflow.com/a/14790376/9335733 . The titles happen to appear over the top x-axis title and so I attempt to move them as suggested here: https://stackoverflow.com/a/44618277/9335733 . The overall code looks as follows:

lapply(names(Cast.files), function (x) plot(Cast.files[[x]],
                                        main = x,
                                        adj = 0, #adjust title to the farthest left
                                        line =2.5 #adjust title up 2.5
                                        )
   )

It should be noted that plot is now converted from base R to the oce package for analyzing oceanographic data, but calls the same arguments from base R plot .

The problem becomes that in trying to move the title, the axis labels move as well and overlap. Any suggestions?

Edit: Here is what the image looks like before: 在此处输入图片说明

And after: 在此处输入图片说明

You might also want to look into the oma= argument in par() , which provides an "outer" margin which can be used to put a nice title. Something like:

library(oce)
data(ctd)
par(oma=c(0, 0, 1, 0))
plot(ctd)
title('Title', outer=TRUE)

This was solved by adding a title argument outside of the plot function as follows:

lapply(names(Cast.files), function (x) plot(Cast.files[[x]], 
                                        which = c("temperature", "salinity", "sigmaT","conductivity"),
                                        Tlim = c(11,12), 
                                        Slim = c(29,32),
                                        col = "red") 
+ title(main = x, adj = 0.48, line = 3.5)#adding the titles at a specific location
   )

This allowed for plots that looked like:

在此处输入图片说明

如果您使用标题功能,而不是在绘图中设置main,则可以在不影响绘图中任何其他内容的情况下更改行。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM