ggplot2的主题系统可以让我们更好的控制图形 非数据元素 的细节,通过更加精细的修改来提升图像的美感,ggplot2 的主题系统自带多个 element_ 功能
本节来介绍主题元素element_text() ,使用它控制绘图中文本元素的许多部分,如字体大小、颜色和字体类型。
library(tidyverse)
library(palmerpenguins)
依旧还是使用企鹅的数据集,接下来使用element_text() 函数来调整图像的文本元素
p<- penguins %>%
drop_na() %>%
ggplot(aes(x=flipper_length_mm,
y=bill_length_mm,
color=species,
shape=sex))+
geom_point()+
labs(title="Palmer Penguins",
subtitle="Flipper Length vs Bill Length",
caption="cmdlinetips.com",
tag = 'A'
)
p
x&y
标签文本通过element_text( )来更改文本,颜色,大小和角度
p + theme(axis.title.x = element_text(size=16, color="purple",
face="bold",angle=0),
axis.title.y = element_text(size=16, color="purple",
face="bold",angle=90))
x&y
刻度文本p + theme(axis.text.x=element_text(family = "Tahoma",face="bold",
colour="black",size=10),
axis.text.y = element_text(family = "Tahoma",face="bold",
colour="black",size=10))
p + theme(legend.title=element_text(color="purple",
face="bold",size=12))
p + theme(legend.text=element_text(face="bold", color="red",size=10))
p + theme(plot.title= element_text(size=15,color="blue",hjust = 0.5,
face="bold",family = "Tahoma"))
p + theme(plot.subtitle= element_text(size=13,
color="red",
face="bold"))
p + theme(plot.caption= element_text(size=12,
color="blue",
face="bold"))
p + theme(plot.tag = element_text(size=16,
color="red",
face="bold"))
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有