如下所示:
title(main = NULL, sub = NULL, xlab = NULL, ylab = NULL, line = NA, outer = FALSE, ...)
參數(shù) | 描述 |
---|---|
main | 主標(biāo)題 |
sub | 副標(biāo)題 |
xlab | x軸標(biāo)簽 |
ylab | y軸標(biāo)簽 |
line | 到軸線的行數(shù)距離 |
outer | 一個(gè)邏輯值。 如果為TRUE,則標(biāo)題位于圖的外部邊緣. |
補(bǔ)充:R語(yǔ)言低級(jí)繪圖函數(shù)-title
title 函數(shù)用來在一張圖表上添加標(biāo)題
基本用法:
main 表示主標(biāo)題,通常位于圖像的上方, sub 表示副標(biāo)題,位于圖像的下方, xlab 表示x軸的標(biāo)簽,ylab 表示y軸的標(biāo)簽
par(oma = c(1, 1, 1, 1)) plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n", xlab = "", ylab = "") box(which = "figure", col = "red", lwd = 2) box(which = "plot", col = "blue", lwd = 2) title(main = "main tilte", sub = "sub title", xlab = "xlab", ylab = "ylab")
效果圖如下:
參數(shù)設(shè)置:
col : 設(shè)置標(biāo)題的顏色
cex : 設(shè)置標(biāo)題的文字大小
font : 設(shè)置標(biāo)題的文字的格式
以上三個(gè)參數(shù)可以針對(duì)不同的標(biāo)題分別進(jìn)行設(shè)置,需要注意的是xlab和ylab 不能分開設(shè)置,只能是同時(shí)設(shè)置,對(duì)應(yīng)的參數(shù)為 col.lab, col.cex, font.cex
代碼示例:
plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n", xlab = "", ylab = "") title(main = "main tilte", sub = "sub title", xlab = "xlab", ylab = "ylab", col.main = "red", cex.sub = 1.5, col.lab = "blue")
效果圖:
outer : 邏輯值,如果為TRUE, 將標(biāo)題放到plot area的外邊
代碼示例:
par(oma = c(5, 5, 3, 3)) plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n", xlab = "", ylab = "") box(which = "figure", col = "red", lwd = 2) box(which = "plot", col = "blue", lwd = 2) title(main = "main tilte", sub = "sub title", xlab = "xlab", ylab = "ylab", outer=TRUE)
效果圖如下:
title 中也允許表達(dá)式
代碼示例:
plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n", xlab = "", ylab = "") title(main = expression(sqrt(x)), sub = expression(x^2), xlab = "xlab", ylab = "ylab")
效果圖如下:
更多關(guān)于表達(dá)式的書寫,可以參考plotmath 函數(shù)的幫助文檔
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持服務(wù)器之家。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教。
原文鏈接:https://blog.csdn.net/t4ngw/article/details/106006556