1.导入其他字体
【R语言】如何在ggplot2里将图片文字改成微软雅黑_Jerryswing的博客-CSDN博客
windowsFonts(A=windowsFont("微软雅黑"))
windowsFonts()#查看已有字体
2.字体、加粗、大小:theme()
p<-ggplot(raw_m, aes(x=ymd(date),y = NOx/1000)) +
geom_area(size = 0.7,fill="#69b3a2", alpha=0.4)+
#alpha透明度
geom_line(color="#69b3a2", size=1)+
scale_x_date(name = "日期",date_breaks = '1 month',date_labels = '%Y-%m-%d')+
scale_y_continuous(expand = c(0,0),
name = 'y轴变量',
limits = c(0,50))+
theme(axis.line = element_line(size = 1,color = 'black'),#轴
axis.title = element_text(size = 15,color = 'black',face = 'bold',family = 'A'),#坐标轴标题
plot.title = element_text(size = 20,color = 'black',face = 'bold',family = 'A'),#总标题
axis.text = element_text(colour = "grey20",size = 15,face = "bold",family = 'sans'))+#坐标轴刻度
labs(title = '')
#保存
ggsave(paste0('test/',file1$port[i],'时间变化2',".jpeg"),p,width = 10,height = 5)
face: bold-加粗;plain-常规
family:字体;通过windowsFonts()查看能使用的字体
A:微软雅黑
3.刻度显示的位置:theme()
#原始数据为一周内平均每天排放量
p<-ggplot(raw_w, aes(x=(week_num),y = NOx/1000)) +
#geom_area(size = 0.7,fill="#69b3a2", alpha=0.4)+#alpha透明度
geom_line(color="black", size=1)+
scale_y_continuous(expand = c(0,0),
name = '排放量( kg / d )',
limits = c(0.5,0.75))+
scale_x_continuous(name = '日期',
expand = c(0,0),
labels = raw_w$week, #坐标刻度显示为星期一~七
breaks = raw_w$week_num)+ #真实坐标为x
theme(axis.line = element_line(size = 1,color = 'black'),#轴
axis.title = element_text(size = 15,color = 'black',face = 'bold',family = 'A'),#坐标轴标题
plot.title = element_text(size = 18,color = 'black',face = 'bold',family = 'A'),#总标题
axis.text = element_text(colour = "grey20",size = 10,face = "bold",family = 'A'),
#vjust hjust 调整位置,angle调整角度
axis.text.x = element_text(vjust =1,hjust = 1,angle = 30),
axis.text.y = element_text(hjust = -10))
4.legend大小修改:theme()
+theme(legend.text = element_text(size = 10,color = 'grey20',face = 'bold',family = 'A'),
legend.title = element_text(size = 12,color = 'grey20',face = 'bold',family = 'A'))
5.legend修改列数:
p + guides(color = guide_legend(ncol = 2))#ncol表示2列