【R语言】【ggplot2】修改图表文字

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列

  • 0
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值