【问题标题】:How to add a jpeg logo to the top lhs outer margin of a base graphics plot?如何将 jpeg 徽标添加到基本图形图的顶部 lhs 外边距?
【发布时间】:2018-08-18 15:43:14
【问题描述】:

我可以使用以下方法将 jpeg 添加到基本图形图上: 参考:Adding a picture to plot in R

require(jpeg)
img <- readJPEG("myfile.jpeg")
#now open a plot window with coordinates
par(oma=c(2, 0, 3, 0))

plot(1:10, ty="n")
mtext("I would like to put logo here", adj=0, cex=1.5, line=1, side=3, outer=TRUE)
#specify the position of the image through bottom-left and top-right coords
rasterImage(img, 2, 2, 4, 4)

但是如何将 jpeg 添加到顶部 lhs 外边距?我有一个标志,我想把它放在那里。

【问题讨论】:

    标签: r plot


    【解决方案1】:

    您可以设置xpd=TRUE 将图像剪辑到图形区域而不是绘图区域。然后在rasterImage() 中只考虑边缘之外的坐标。您将不得不对par()rasterImage() 位置向量进行一些操作。

    示例

    par(oma=c(2, 0, 5, 0), xpd=TRUE)  # c(bottom, left, top, right)
    plot(1:10, ty="n")
    rasterImage(img, -0.5, 12, 3, 15)  # c(xleft, ybottom, xright, ytop)
    

    图像数据

    library(png)
    myurl <- "https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-logo.png?v=9c558ec15d8a"
    z <- tempfile()
    download.file(myurl,z,mode="wb")
    img <- readPNG(z)
    file.remove(z)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-05-27
      • 2019-08-31
      • 1970-01-01
      • 2012-05-04
      • 1970-01-01
      • 2021-06-26
      • 2018-08-07
      相关资源
      最近更新 更多