美文网首页
给大家拜年啦:恭祝大家在牛年 学术财路双开花,脱单脱贫不脱发

给大家拜年啦:恭祝大家在牛年 学术财路双开花,脱单脱贫不脱发

作者: 小明的数据分析笔记本 | 来源:发表于2021-02-12 16:53 被阅读0次

今天在朋友圈看到有人发的拜年文案,借这个文案给大家拜个年:祝大家在新的一年里 学术财路双开花,脱贫脱单不脱发 文章 张口就来

image.png

下面介绍上面这幅图的实现方法

首先是ggplot2画图,用图片作为填充背景
library(ggplot2)
library(jpeg)
library(ggpubr)
img<-readJPEG("1-2.jpg")
p<-ggplot()+
  background_image(img)+
  theme_void()
pdf("Rplot19.pdf",width = 8.5,height = 5)
p
dev.off()
image.png
添加红色背景
p<-ggplot()+
  background_image(img)+
  xlim(0,10)+ylim(0,10)+
  theme_void()+
  geom_rect(aes(xmin=3.5,xmax=4.5,ymin=0,ymax=8),fill="red")+
  geom_rect(aes(xmin=5.5,xmax=6.5,ymin=0,ymax=8),fill="red")+
  geom_rect(aes(xmin=4,xmax=6,ymin=9,ymax=10),fill="red")
p
image.png
添加文字
p<-ggplot()+
  background_image(img)+
  xlim(0,10)+ylim(0,10)+
  theme_void()+
  geom_rect(aes(xmin=3.5,xmax=4.5,ymin=0,ymax=8),fill="red")+
  geom_rect(aes(xmin=5.5,xmax=6.5,ymin=0,ymax=8),fill="red")+
  geom_rect(aes(xmin=3.8,xmax=6.2,ymin=9,ymax=10),fill="red")+
  annotate(geom = "text",x=6,y=4,
           label="学\n术\n财\n路\n双\n开\n花",
           size=8)+
  annotate(geom = "text",x=4,y=4,
           label="脱\n贫\n脱\n单\n不\n脱\n发",
           size=8)+
  annotate(geom = "text",x=4.8,y=9.5,
           label="“章”口就来",
           size=8)
p
完整代码
library(ggplot2)
library(jpeg)
library(ggpubr)
library(extrafont)
fonts()
library(Cairo)
img<-readJPEG("1-2.jpg")
p<-ggplot()+
  background_image(img)+
  xlim(0,10)+ylim(0,10)+
  theme_void()+
  geom_rect(aes(xmin=3.5,xmax=4.5,ymin=0,ymax=8),fill="red")+
  geom_rect(aes(xmin=5.5,xmax=6.5,ymin=0,ymax=8),fill="red")+
  geom_rect(aes(xmin=3.8,xmax=6.2,ymin=9,ymax=10),fill="red")+
  annotate(geom = "text",x=6,y=4,
           label="学\n术\n财\n路\n双\n开\n花",
           size=8)+
  annotate(geom = "text",x=4,y=4,
           label="脱\n贫\n脱\n单\n不\n脱\n发",
           size=8)+
  annotate(geom = "text",x=4.8,y=9.5,
           label="“章”口就来",
           size=8)
ggsave("Happy_Niu_Year.pdf",p,width = 8.5,height = 5,
       family="STKaiti",
       device = cairo_pdf)
pdf("Rplot20.pdf",width = 8.5,height = 5)
p
dev.off()
image.png

高清图片可在后台留言 牛转乾坤 获取

欢迎家关注我的公众号
小明的数据分析笔记本

公众号 主要分享:1、R语言和python做数据分析和数据可视化的简单小例子;2、园艺植物相关转录组学、基因组学、群体遗传学文献阅读笔记!

相关文章

网友评论

      本文标题:给大家拜年啦:恭祝大家在牛年 学术财路双开花,脱单脱贫不脱发

      本文链接:https://www.haomeiwen.com/subject/rfdrxltx.html