背景画像上にいくつかのデータをプロットしようとしています。問題は、両方のレイヤーが同じスケールで終了することです。これは残念ながら問題です。ggplotを使用して背景画像にデータをプロット
例。
これ以上のデータをプロットしたいです。image
右。だから私はそれをggplotにプロットします。
img <- readJPEG("image.jpg")
image <- apply(img, 1:2, function(v) rgb(v[1], v[2], v[3]))
image <- melt(image)
ggplot(image, aes(row, -column, fill=fill)) + geom_tile() + scale_fill_identity()
これはうまくいきます。だから、上にいくつかのデータを追加しましょう。
df <- data.frame(x=sample(1:64, 1000, replace=T),
y=sample(1:64, 1000, replace=T))
ggplot(df, aes(x,y)) + stat_bin2d()
サンプルデータをプロットすると、thisが得られます。
このデータプロットをグラデーションイメージの上に重ねてください。
ggplot(image, aes(row, -column, fill=fill)) + geom_tile() +
scale_fill_identity() + geom_point(data=df2, aes(x=x, y=-y))
しかし、それは第二フィルスケールはエラーをスロー指定しようとするとthis
のように終わります。私はthisはできないと言いますが、回避策があるか、または私が見落としているものがあることを期待しています。
[これ](http://kohske.wordpress.com/2010/12/26/use-image-for-background(あるいはannotation_raster又は)、これを試してみてください-in-ggplot2 /)の投稿は古く、新しいバージョンのggplotを更新する必要がありますが、少なくとも回避方法を提案するかもしれません。 – joran