最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2023年02月13日 10:44:31   作者:我是大南瓜  
ggplot2是一個強大的作圖工具,它可以讓你不受現(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. 實際應(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)文章

最新評論

阳西县| 香港| 教育| 洪泽县| 岑巩县| 长寿区| 绍兴市| 灵丘县| 长春市| 商洛市| 孟州市| 贺州市| 醴陵市| 清水县| 徐州市| 松溪县| 枣庄市| 卢氏县| 禹城市| 夏邑县| 婺源县| 灌阳县| 革吉县| 道孚县| 潢川县| 页游| 义乌市| 盐池县| 卓尼县| 双牌县| 芦山县| 武平县| 吴旗县| 遂川县| 隆化县| 德保县| 察哈| 双城市| 遂宁市| 双鸭山市| 泰和县|