📜  在 R 编程中为图形添加标题 – title()函数

📅  最后修改于: 2022-05-13 01:54:33.467000             🧑  作者: Mango

在 R 编程中为图形添加标题 – title()函数

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

示例 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:副标题的文字大小

示例 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
  )

输出: