ggthemes主题

常用主题:https://blog.csdn.net/qq_27755195/article/details/52105087

我常用theme_few主题 theme_few(base_family="字体")###显示主题中的的字体

链接

微信

改变画图区域图的页边距

p+theme(plot.margin=unit(rep(1,4),'lines'))#lines是单位,rep=c(1,1,1,1)

2022-04-22更新

p+theme(text = element_text(family = "ST_TNR",size=22),#控制全局字体,包括坐标轴标签及刻度
plot.title = element_text(hjust=0.5),#控制标题位置
axis.ticks.length.y = unit(-0.2,"cm"),#控制y轴刻度向内,长度0.2
axis.ticks.length.x = unit(-0.2,"cm"),#控制x轴刻度向内,长度0.2
panel.border =element_blank(),#隐藏所有框线
axis.line = element_line(color = 'black'),#添加左侧和下侧框线,黑色
plot.margin = unit(rep(0.3,4),'cm'))#控制画图区域页边距,rep()表重复

修改全局字体

p + theme(text = element_text(family = "ST_TNR",size=22),#控制全局字体,包括坐标轴标签及刻度
#####这一行一定要在theme_few()函数后面

或者
theme_few(base_family = "ST_TNR",base_size=14)

左右控制坐标轴数字标签

p+theme(axis.ticks.length.y = unit(-0.3,"cm"),axis.ticks.length.x = unit(-0.3,"cm"),axis.text.x = element_text(hjust = -0.3))

修改图例位置

#隐藏图例
theme(legend.position=c(null))

#移动图例位置left,right,top,bottom
theme(legend.position="top")

#移动图例位置
theme(legend.position=c(0.11,0.75))

控制图例位置,大小,边距

theme(legend.position="bottom",
legend.key.height = unit(0.4,'cm'),
legend.key.width = unit(0.4,'cm'),
legend.margin = margin(-0.2,0,0,0,'cm'))