我正在尝试在背景图像上绘制一些数据。问题是两个层最终都使用相同的比例。不幸的是,这是有问题的。
一个例子。
我想绘制一些数据image https://dl.dropboxusercontent.com/u/39251/image.jpg.
正确的。所以我像这样在 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()
Plotting the sample data, I get this https://dl.dropboxusercontent.com/u/39251/data.png.
所以我只希望这个数据图分层在梯度图像上。
ggplot(image, aes(row, -column, fill=fill)) + geom_tile() +
scale_fill_identity() + geom_point(data=df2, aes(x=x, y=-y))
但它最终就像this https://dl.dropboxusercontent.com/u/39251/ugly.png
尝试指定第二个填充比例会引发错误。我懂了this https://stackoverflow.com/questions/11752709/using-two-scale-colour-gradients-on-one-ggplot说这是不可能完成的,但我希望有一个解决方法或我忽略的东西。