R 如何以png为背景进行打印?
我用300万点绘制了一个图,并将其保存为PNG。这花了几个小时,我想避免重画所有的要点 如何生成以此PNG为背景的新绘图?试试以下方法:R 如何以png为背景进行打印?,r,data-visualization,large-data,R,Data Visualization,Large Data,我用300万点绘制了一个图,并将其保存为PNG。这花了几个小时,我想避免重画所有的要点 如何生成以此PNG为背景的新绘图?试试以下方法: 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 are
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")
库(png)
#用您的信息替换目录和文件信息
ima虽然@bill_080的答案直接回答了你的问题,但这真的是你想要的吗?如果你想在上面绘图,你必须小心地对齐你的坐标系。例如,请参见如何使用ggplot2完成此操作
对于您的问题,在我看来可能有一个更简单的解决方案:装箱,即对二维直方图进行装箱
> df <- data.frame (x = rnorm (1e6), y = rnorm (1e6))
> system.time (plot (df))
User System verstrichen
54.468 0.044 54.658
> library (hexbin)
> system.time (binned <- hexbin (df, xbins=200))
User System verstrichen
0.252 0.012 0.266
> system.time (plot (binned))
User System verstrichen
0.704 0.040 0.784
但您可以轻松地使用颜色编码密度:
> plot (binned@xcm, binned@ycm, pch = 20, cex=0.4, col = as.character (col))
> col <- cut (binned@count, 20)
> levels (col) <- grey.colors (20, start=0.9, end = 0)
> plot (binned@xcm, binned@ycm, pch = 20, cex=0.4, col = as.character (col))
>绘图(binned@xcm, binned@ycm,pch=20,cex=0.4,col=as.character(col))
>col水平(col)图(binned@xcm, binned@ycm,pch=20,cex=0.4,col=as.character(col))
从未使用过它,但packagepng
可能有你想要的:最好给你的积分增加一些透明度,这样你可以更好地看到它们的分布。就像密度图一样,看一看
> plot (binned@xcm, binned@ycm, pch = 20, cex=0.4, col = as.character (col))
> col <- cut (binned@count, 20)
> levels (col) <- grey.colors (20, start=0.9, end = 0)
> plot (binned@xcm, binned@ycm, pch = 20, cex=0.4, col = as.character (col))