R 添加图片

R 添加图片

在R的绘图对象中添加图片,以下列举两种方法。

图片对象

library(ggplot2)
gg <- ggplot(mpg, aes(displ, hwy, colour = class)) +  geom_point()

静态图片

library(png)
logo <- readPNG('E:/logo.png')

通过 grid

grid.newpage()
print(gg)
vp <- viewport(x = 0.6, y = 0.3, width = 0.2, height = 0.2)
grid.raster(logo, vp = vp)

在这里插入图片描述

通过ggplot2

gg + annotation_custom(
    rasterGrob(logo, width=unit(1,"npc"), height=unit(1,"npc")),
     xmin = 5, xmax = 6, ymin = 30, ymax = 40
    )

在这里插入图片描述

plot 绘制图片

  par(mar = c(0,0,0,0))
  plot(0, 1, type = 'n', xlim = c(0,1), ylim = c(0,1), ann = F, bty = "n", xaxt = "n", yaxt ="n")
  rasterImage(logo, 0.25,0.25,0.75,0.75)

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值