我想ggplot2用一种方式覆盖两个带有alpha通道的图,结果图像显示两个数据集.这是我的测试数据:
data = read.table(text="P1 -1 0 4\nP2 0 0 2\nP3 2 1 8\nP4 -2 -2 6\nP5 0.5 2 12")
data2 = read.table(text="Q1 1 1 3\nQ2 1 -1 2\nQ3 -1 1 8")
colnames(data) = c("name","x","y","score")
colnames(data2) = c("name","x","y","score")
Run Code Online (Sandbox Code Playgroud)
这是我如何绘制这些数据:
ggplot(data, aes(x=x,y=y)) +
stat_density2d(data=data,geom="tile", aes(fill = ..density..,alpha=..density..), contour=FALSE) +
theme(legend.position="none") + scale_fill_gradient (low = "#FFFFFF", high = "#FF0000") +
xlim(-3,3) + ylim(-3,3) +
geom_point()
ggplot(data2, aes(x=x,y=y)) +
stat_density2d(data=data2,geom="tile", aes(fill = ..density..,alpha=..density..), contour=FALSE) +
theme(legend.position="none") +
scale_fill_gradient (low = "#FFFFFF", high …Run Code Online (Sandbox Code Playgroud)