ggplot2-跨多个绘图的通用色标

时间:2018-09-04 22:20:53

标签: r ggplot2 colors scale

我有两个具有不同最小值和最大值的数据集,请参见数据帧df1和df2中的“ z”。

问题:如何定义两个数据集的颜色,以便生成的图,即它们的颜色条比例有意义?

df1 <- data.frame(
  x = rep(c(2, 4, 6, 8, 10), 2),
  y = rep(c(1, 2), each = 5),
  z = c(0.00e+00,4.56e-03,3.93e-04,4.89e-05,1.63e-02,
        2.59e-02,1.06e-02,-2.87e-04,-3.28e-03,-4.90e-04)
)
ggplot(df1, aes(x, y)) +
  geom_tile(aes(fill = z), colour = "grey50")

df2 <- data.frame(
  x = rep(c(2, 4, 6, 8, 10), 2),
  y = rep(c(1, 2), each = 5),
  z = c(0.00e+00,-2.94e+00,9.64e-01,8.00e-01,-1.29e-05,
        0.00e+00,-3.65e-04,8.09e+00,-2.94e-03,-9.75e-01)
)
ggplot(df2, aes(x, y)) +
  geom_tile(aes(fill = z), colour = "grey50")

enter image description here

enter image description here

0 个答案:

没有答案