ggplot2组合绘制多个图形

在这里插入图片描述

win.graph()
library(ggplot2)
library(cowplot)
library(showtext)
font_add_google("Dancing Script", "Dancing")
图1
plot.iris <- ggplot(iris, aes(Sepal.Length, Sepal.Width)) +
     geom_point() +
 facet_grid(cols = vars(Species)) # 按Species列分面
图2
plot.mpg <- ggplot(mpg, aes(x = cty, y = hwy, colour = factor(cyl))) +
   geom_point(size = 2.5) +    labs(title = "dot plot") 
图3
plot.diamonds <- ggplot(diamonds, aes(clarity, fill = cut)) +
   geom_bar() +
   theme(axis.text.x = element_text(angle = 70, vjust = 0.5)) +
   labs(title = "bar plot")
组合绘图叠加
gg <- ggdraw() + 
    draw_plot(plot.iris, 0, 0.5, 1, 0.5) + draw_plot(plot.mpg, 0, 0, 0.5, 0.5) +
 # 在母图上半部,占母图比例1/2  
 # 在母图左下角,占母图比例1/4  

draw_plot(plot.diamonds, 0.5, 0, 0.5, 0.5) + 

 # 在母图右下角,占母图比例1/4 
draw_plot_label(c("A", "B", "C"), c(0, 0, 0.5), c(1, 0.5, 0.5), size = 15,colour = "cyan", family = "Dancing") # 加上标签,
浏览图形
showtext_begin()
print(gg)
showtext_end()

在这里插入图片描述

  • 11
    点赞
  • 56
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值