如何增加Base R Plot的字体大小

如何增加Base R Plot的字体大小

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

语法

plot(x, y, main=”title”, sub=”subtitle”)

cex 属性是整数,它是比例因子的指标,描述了图中元素可以被缩放的量。默认值是1,0.5减少50%,等等。cex参数可以有整数或小数值。

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

选项 描述
cex.axis 轴注释的放大率
cex.lab 轴的X和Y标签的放大率
cex.main 主标题的放大率
cex.sub 副标题的放大倍数

下面的图表已经被用来参考,以创建不同的组件,默认情况下,字体大小=1。它显示的是方程y = x2 的图形, 其中x值是用R中的seq()函数创建的。这有助于更好地理解图形,其差异也很明显。

例子

# 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)
Bash

输出

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

增加标签的字体大小

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)
Bash

输出

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

增加轴的字体大小

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)
Bash

输出

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

增加主标题的字体大小

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)
Bash

输出

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

增加副标题的大小

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)
Bash

输出

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

增加图形的所有属性

为了增加属性的大小,所有的属性连同它们各自的值都要传递给函数。

例子

# 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)
Bash

输出

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

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

登录

注册