300万ポイントのプロットを作成し、PNGとして保存しました。数時間かかりましたが、すべてのポイントを再描画しないようにしたいと思います。
このPNGを背景とする新しいプロットを生成するにはどうすればよいですか?
回答:
回答№1の79これを試して:
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")
以下はプロットです。
回答№2の15
@ bill_080 "の答えはあなたの質問に直接答えますが、これは本当にあなたが望むものですか?これにプロットしたい場合、あなたはあなたの座標系を注意深く整列させる必要があります。例参照 ヒューストン犯罪地図 ggplot2を使用してこれを行う方法。
あなたの問題については、より簡単な解決策があるかもしれないと思われます:ビニング、つまり2Dヒストグラムを止めることです。
> 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
hexbinは、格子とggplot2で直接動作しますが、ビンの中心座標は binned@xcm
そして binned@ycm
、したがって、ベースグラフィックスで結果をプロットすることもできます。ビンの数が多いと、元のプロットの高速バージョンが得られます。
> system.time (plot (binned@xcm, binned@ycm, pch = 20, cex=0.4))
User System verstrichen
0.780 0.004 0.786
ただし、密度をコーディングする色を簡単に設定できます。
> 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))