【发布时间】:2019-03-22 03:10:44
【问题描述】:
我有一个矩阵,我想制作一个等高线图。起初,我尝试了 R 中的 contour 函数,得到了下图。
但是,轮廓线不平滑,x & y 标签也不正确。所以我想用ggplot2 来制作一个平滑的等高线图。但是,ggplot2 会产生错误:
Computation failed in `stat_contour()`:
Contour requires single `z` at each combination of `x` and `y`.
数据可在https://www.dropbox.com/s/1obn2xxcra10usl/data1.rdata?dl=0获取
load("data1.rdata",.GlobalEnv)
contour(data1)
这是我在ggplot2中尝试使用的代码:
library(reshape2)
library(ggplot2)
data1_melt = melt(data1)
names(data1_melt) <- c("y", "x", "pr")
ggplot(data1_melt, aes(x = x, y = y, z = pr)) + stat_contour()
【问题讨论】: