【问题标题】:ReadPng, raster, width of picture in the background of a plotReadPng,光栅,绘图背景中图片的宽度
【发布时间】:2016-06-23 18:59:40
【问题描述】:

我正在尝试以 png 作为背景进行绘图 as this post :所以我使用了这段代码

library(png)

#Replace the directory and file information with your info
ima <- readPNG("C:\\Documents and Settings\\Bill\\Data\\R\\Data\\Images\\sun.png")

#Set up the plot area
plot(1:2, type='n', main="Plotting Over an Image", xlab="x", ylab="y")

#Get the plot information so the image will fill the plot box, and draw it
lim <- par()
rasterImage(ima, lim$usr[1], lim$usr[3], lim$usr[2], lim$usr[4])
grid()
lines(c(1, 1.2, 1.4, 1.6, 1.8, 2.0), c(1, 1.3, 1.7, 1.6, 1.7, 1.0), type="b", lwd=5, col="white")

问题是我无法在显示中找到修改或指定图片宽度和高度的方法。

如何做到这一点?

【问题讨论】:

    标签: r plot


    【解决方案1】:

    这就是我所做的,它对我有用。宽度= 1552 和高度= 112。添加 ylim 和 xlim,调整窗口大小并在 rasterImage 函数中修复 with 和 height 修复问题。

    resize.win <- function(Width=6, Height=6)
    {
        dev.off();
        windows(record=TRUE, width=Width, height=Height)
    }
    resize.win(1552,300)
    library(png)
    #Replace the directory and file information with your info
    img <- readPNG("C:\\Users\\Bill\\Desktop\\plan.png")
    height<-dim(img)[1]
    width<-dim(img)[2]
    
    #Set up the plot area
    plot(1:2, type='n', main="Plotting Over an Image", xlab="x", ylab="y", xlim=c(1,width),ylim=c(1,height))
    
    #Get the plot information so the image will fill the plot box, and draw it
    lim <- par()
    rasterImage(img,0,0,width,height)
    grid()
    lines(c(19, 1.2, 1.4, 1.6, 1.8, 2.0), c(69, 1.3, 1.7, 1.6, 1.7, 1.0), type="b", lwd=5, col="black")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-11-23
      • 2014-10-03
      • 1970-01-01
      • 2015-03-19
      • 2014-09-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多