欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

R語言ggplot2?title設(shè)置教程(main,axis和legend?titles)

 更新時間:2023年02月13日 10:44:31   作者:我是大南瓜  
ggplot2是一個強(qiáng)大的作圖工具,它可以讓你不受現(xiàn)有圖形類型的限制,創(chuàng)造出任何有助于解決你所遇到問題的圖形,下面這篇文章主要給大家介紹了關(guān)于R語言ggplot2?title設(shè)置(main,axis和legend?titles)的相關(guān)資料,需要的朋友可以參考下

1. ggplot2中添加title函數(shù)

ggtitle(label) # for the main title,主題目
xlab(label) # for the x axis label, xlab
ylab(label) # for the y axis label, ylab
labs(...) # for the main title, axis labels and legend titles,可以同時設(shè)定多個lab和tittle

2. 實(shí)際應(yīng)用

(1)添加title、xlab和ylab

ToothGrowth$dose <- as.factor(ToothGrowth$dose)
library(ggplot2)
p <- ggplot(ToothGrowth, aes(x=dose, y=len)) + geom_boxplot()
## 方法1:
p + ggtitle("Plot of length \n by dose") +
  xlab("Dose (mg)") + ylab("Teeth length")

## 方法2:
p +labs(title="Plot of length \n by dose",
        x ="Dose (mg)", y = "Teeth length")

(2)修改legend名字

# Default plot
p <- ggplot(ToothGrowth, aes(x=dose, y=len, fill=dose))+
  geom_boxplot()
p
# Modify legend titles
p + labs(fill = "Dose (mg)")

(3)修改title的字體,位置,顏色等

參數(shù),其中hjust和vjust可以調(diào)節(jié)位置, anglexlab和ylab調(diào)節(jié)角度,size可以調(diào)節(jié)label大?。?/p>

family : font family
face : font face. Possible values are “plain”, “italic”, “bold” and “bold.italic”
colour : text color
size : text size in pts
hjust : horizontal justification (in [0, 1])
vjust : vertical justification (in [0, 1])
lineheight : line height. In multi-line text, the lineheight argument is used to change the spacing between lines.
color : an alias for colour
angle: angle

使用:

# Default plot
p <- ggplot(ToothGrowth, aes(x=dose, y=len)) + geom_boxplot() +
  ggtitle("Plot of length \n by dose") +
  xlab("Dose (mg)") + ylab("Teeth length")
p
# Change the color, the size and the face of
# the main title, x and y axis labels
p + theme(
plot.title = element_text(color="red", size=14, face="bold.italic"),
axis.title.x = element_text(color="blue", size=14, face="bold"),
axis.title.y = element_text(color="#993333", size=14, face="bold")
)

此外,修改坐標(biāo)軸的angle也是相似的構(gòu)造:

require(ggplot2)
ggplot(data=mtcars, aes(x=mpg, y=wt)) + geom_point()  + theme(axis.text.x = element_text(angle=90))
ggplot(data=mtcars, aes(x=mpg, y=wt)) + geom_point()  + theme(axis.text.y = element_text(angle=90))

(4)刪除xlab和ylab

# Hide the main title and axis titles
p + theme(
  plot.title = element_blank(),
  axis.title.x = element_blank(),
  axis.title.y = element_blank())

總之,一次性設(shè)定ggplot相關(guān)title的話, labs(title=" ", x=" ",y=" ")即可,修改需要使用后面的theme(axis.text.x = element_text(angle=90)),類似這種設(shè)定。

翻譯來源:

http://www.sthda.com/english/wiki/ggplot2-title-main-axis-and-legend-titles

總結(jié)

到此這篇關(guān)于R語言ggplot2 title設(shè)置教程(main,axis和legend titles)的文章就介紹到這了,更多相關(guān)R語言ggplot2 title設(shè)置內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • R語言寫2048游戲?qū)嵗v解

    R語言寫2048游戲?qū)嵗v解

    這篇文章主要介紹了R語言寫2048游戲?qū)嵗v解,文中將代碼列舉了出來,有感興趣的同學(xué)可以學(xué)習(xí)下
    2021-03-03
  • R語言實(shí)現(xiàn)操作MySQL數(shù)據(jù)庫

    R語言實(shí)現(xiàn)操作MySQL數(shù)據(jù)庫

    這篇文章主要介紹了R語言實(shí)現(xiàn)操作MySQL數(shù)據(jù)庫,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-03-03
  • R語言表達(dá)式知識點(diǎn)總結(jié)

    R語言表達(dá)式知識點(diǎn)總結(jié)

    在本篇文章里小編給大家整理了一篇關(guān)于R語言表達(dá)式知識點(diǎn)總結(jié)內(nèi)容,有興趣的朋友們可以學(xué)習(xí)參考下。
    2021-03-03
  • R語言中aggregate?函數(shù)詳解

    R語言中aggregate?函數(shù)詳解

    這篇文章主要介紹了R語言中aggregate?函數(shù)的相關(guān)資料,aggregate函數(shù)是數(shù)據(jù)處理中常用到的函數(shù),具有強(qiáng)大的功能,可以按照要求把數(shù)據(jù)打組聚合,然后對聚合以后的數(shù)據(jù)進(jìn)行加和、求平均等各種操作,需要的朋友可以參考下
    2023-04-04
  • 用R語言繪制函數(shù)曲線圖

    用R語言繪制函數(shù)曲線圖

    這篇文章主要介紹了如何用R語言繪制函數(shù)曲線圖,幫助大家更好的理解和學(xué)習(xí)使用R語言,感興趣的朋友可以了解下
    2021-03-03
  • R語言 檢驗多重共線性的操作

    R語言 檢驗多重共線性的操作

    這篇文章主要介紹了R語言 檢驗多重共線性的操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-04-04
  • 基于R語言?數(shù)據(jù)檢驗詳解

    基于R語言?數(shù)據(jù)檢驗詳解

    這篇文章主要介紹了R語言數(shù)據(jù)檢驗的相關(guān)知識,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-03-03
  • R語言實(shí)現(xiàn)ggplot重繪天貓雙十一銷售額曲線圖過程

    R語言實(shí)現(xiàn)ggplot重繪天貓雙十一銷售額曲線圖過程

    這篇文章主要為大家介紹了如何使用ggplot繪制天貓雙十一銷售額曲線圖的實(shí)現(xiàn)過程,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2021-11-11
  • 基于R語言中的各種更新方法分享

    基于R語言中的各種更新方法分享

    這篇文章主要介紹了基于R語言中的各種更新方法分享,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-04-04
  • R語言拼接字符串_paste的用法說明

    R語言拼接字符串_paste的用法說明

    這篇文章主要介紹了R語言拼接字符串_paste的用法說明,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-04-04

最新評論