当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


R语言 title()用法及代码示例


R 语言中的 title() 函数用于为图形添加主标题和轴标题。此函数还可用于修改现有标题。

用法:
title(main = NULL, sub = NULL, xlab = NULL, ylab = NULL, …)

参数:
main:图表的主标题
sub:定义字幕

返回:添加标题后的绘图

范例1:




# R program to add title to a Graph
  
# Specifying axis values
x<-1:5; y<-x*x
  
# Creating a plot
plot(x, y, main = "", xlab = "", ylab = "",
     col.axis = "darkgreen") 
  
# Calling title() function
title(main = "Graph ", sub = "Geeksforgeeks article",
      xlab = "X axis", ylab = "Y axis",
      cex.main = 4,   font.main = 3, col.main = "darkgreen",
      cex.sub = 2, font.sub = 3, col.sub = "darkgreen",
      col.lab ="black"
      )

输出:

在上面的例子中,主标题和副标题被添加到情节中。可用于更改字体大小的参数如下:

  • cex.main:主标题的大小
  • cex.lab:轴标题的文本大小
  • cex.sub:sub-title 的文字大小

范例2:


barplot(c(1, 10) )
title(main = "PLOT ", sub = "Geeksforgeeks article",
      xlab = "X axis", ylab = "Y axis",
  
  # Change the colors
  col.main="darkgreen", col.lab="black", col.sub="darkgreen",
  
  # Titles in italic and bold
  font.main = 4, font.lab = 4, font.sub = 3,
  
  # Change font size
  cex.main = 3, cex.lab = 1.7, cex.sub = 2
  )

输出:




相关用法


注:本文由纯净天空筛选整理自kaurbal1698大神的英文原创作品 Add Titles to a Graph in R Programming – title() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。