如何为R中的每个图添加标题? [英] How to add a title to each plot in R?

查看:84
本文介绍了如何为R中的每个图添加标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码将在一个窗口上显示多个图.由于每个图都是根据名为 X1 到 X13 的每一列生成的.所以我想在每个图中添加 作为主要 用于绘制图形的列的名称见下文以区分哪个.

This code will show several plots on one window. As each plot was produced according to each column named X1 to X13 . SO I want to add as a main to each figure the name of the column used to plot the figure see below to distinguish which is which.

ref= read.table("D:\\AS_asc.txt", sep="",header=TRUE)
sour1 = read.table("D:\\re.txt", sep="",header=TRUE) 
sour2= read.table("D:\\_asc.txt", sep="",header=TRUE)
columns <- paste0("X", 1:13)
par(mfrow=c(4,4))
 lapply(
 columns,
 function(column)
  {
   result1 <- (
    mean(ref[[column]]) - 
     ((sd(ref[[column]]) / sd(sour1[[column]])) * mean(sour1[[column]])) + 
     ((sd(ref[[column]]) / sd(sour1[[column]]) * sour1[[column]]))
     )   # calculate using ref and sour1
     result2 <- ((  
      mean(ref[[column]]) - 
      ((sd(ref[[column]]) / sd(sour2[[column]], na.rm=TRUE)) * mean(sour2[[column]], na.rm=TRUE)) + 
     ((sd(ref[[column]]) / sd(sour2[[column]], na.rm=TRUE) * sour2[[column]])) 
    ))  # calculate using ref and sour2
      plot(
    ref[[column]],
    result1,
    ylab = "[[column]]",
    xlab = "[[column]]",
   col  = 2
    )

   points(ref[[column]], ref[[column]], col = 'green')
  points(ref[[column]], result2, col = 'blue')
   }
   )

推荐答案

我相信您可以将其调整到您的代码中,但这就像在您的代码中添加 main = paste(column) 一样简单绘图命令.

I'm sure you can adapt this into your code, but it's as simple as adding main = paste(column) inside your plot command.

示例:

columns <- paste0( "X" , 1:9 )
par(mfrow=c(3,3))
lapply( columns , function(column){ plot(1:10 , y = 1:10 , main = paste(column ) ) } )

这篇关于如何为R中的每个图添加标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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