📜  如何在 Base R Plot 中增加字体大小?

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

如何在 Base R Plot 中增加字体大小?

R 编程语言中的 plot() 方法用于在图中绘制一系列点,并使用它们遵循的曲线和散点将它们可视化。

句法:

cex属性是一个整数,它是比例因子的指标,它描述了绘图元素可以缩放的量。默认值为 1,0.5 将其减少 50% 等。cex 参数可能具有整数或十进制值。

可以使用 plot 方法中的 main 选项在 plot 中添加主标题以传达更多特征,而可以使用 sub 属性添加副标题。可以分别使用 cex.main 选项和副标题使用 cex.sub 选项修改主标题标题的大小。



optionDescription
cex.axismagnification of axis annotation
cex.lab magnification of x and y labels of the axes
cex.main magnification of main title
cex.sub magnification of subtitle

下图已被用作参考,以创建默认缩放为字体大小 = 1 的不同组件。它显示方程 y = x 2的图形其中 x 值是使用 R 中的 seq()函数创建的。这有助于更好地理解图形,并且差异也很明显。

例子:

R
# declaring a sequence of integers
xpos <- seq(0.1 , length.out = 50,by = 0.1)
  
# computing its square
ypos <- xpos**2
  
main_title <- "Squares of numbers"
  
# plotting the data
plot(xpos, ypos, main = main_title)


R
# declaring a sequence of integers
xpos <- seq(0.1 , length.out = 50,by = 0.1)
  
# computing its square
ypos <- x**2
  
main_title <- "Squares of numbers"
  
# plotting the data
plot(xpos, ypos, main = main_title, cex.lab = 2)


R
# declaring a sequence of integers
xpos <- seq(0.1 , length.out = 50,by = 0.1)
  
# computing its square
ypos <- xpos**2
  
main_title <- "Squares of numbers"
  
# plotting the data
plot(xpos, ypos, main = main_title, cex.axes = 2)


R
# declaring a sequence of integers
xpos <- seq(0.1 , length.out = 50,by = 0.1)
  
# computing its square
ypos <- xpos**2
  
main_title <- "Squares of numbers"
  
# plotting the data
plot(xpos, ypos, main = main_title, cex.main = 2)


R
# declaring a sequence of integers
xpos <- seq(0.1 , length.out = 50,by = 0.1)
  
# computing its square
ypos <- xpos**2
  
main_title <- "Squares of numbers"
sub_title <- "Integers"
  
# plotting the data
plot(xpos, ypos, main = main_title , sub= sub_title , cex.sub = 2)


R
# declaring a sequence of integers
xpos <- seq(0.1 , length.out = 50,by = 0.1)
  
# computing its square
ypos <- xpos**2
  
main_title <- "Squares of numbers"
sub_title <- "Integers"
  
# plotting the data
plot(xpos, ypos, main = main_title , sub= sub_title , cax.lab = 1.9, 
     cex.axes = 1.52, cex.main = 2.5, cex.sub = 2)


输出:

增加标签的字体大小

cex.lab 属性可用于修改(x 和 y)轴标签的字体大小。以下代码片段说明了使标签字体大小加倍的过程。

例子:

电阻



# declaring a sequence of integers
xpos <- seq(0.1 , length.out = 50,by = 0.1)
  
# computing its square
ypos <- x**2
  
main_title <- "Squares of numbers"
  
# plotting the data
plot(xpos, ypos, main = main_title, cex.lab = 2)

输出:

增加轴的字体大小

cex.axes 属性可用于修改轴刻度标签的字体大小。只需传递您希望字体增加的值。

例子:

电阻

# declaring a sequence of integers
xpos <- seq(0.1 , length.out = 50,by = 0.1)
  
# computing its square
ypos <- xpos**2
  
main_title <- "Squares of numbers"
  
# plotting the data
plot(xpos, ypos, main = main_title, cex.axes = 2)

输出:

增加主标题的字体大小

cex.main 属性可用于修改为图形指定的主标题的字体大小。

例子:

电阻



# declaring a sequence of integers
xpos <- seq(0.1 , length.out = 50,by = 0.1)
  
# computing its square
ypos <- xpos**2
  
main_title <- "Squares of numbers"
  
# plotting the data
plot(xpos, ypos, main = main_title, cex.main = 2)

输出:

增加子标题的大小

cex.sub 属性可用于修改为图形指定的副标题的字体大小。

例子:

电阻

# declaring a sequence of integers
xpos <- seq(0.1 , length.out = 50,by = 0.1)
  
# computing its square
ypos <- xpos**2
  
main_title <- "Squares of numbers"
sub_title <- "Integers"
  
# plotting the data
plot(xpos, ypos, main = main_title , sub= sub_title , cex.sub = 2)

输出:

增加图的所有属性

为了增加属性的大小,所有属性及其各自的值都被传递给函数。

例子:

电阻

# declaring a sequence of integers
xpos <- seq(0.1 , length.out = 50,by = 0.1)
  
# computing its square
ypos <- xpos**2
  
main_title <- "Squares of numbers"
sub_title <- "Integers"
  
# plotting the data
plot(xpos, ypos, main = main_title , sub= sub_title , cax.lab = 1.9, 
     cex.axes = 1.52, cex.main = 2.5, cex.sub = 2)

输出