【发布时间】:2015-12-08 08:50:35
【问题描述】:
我是 R 新手,并试图在同一个图中绘制多个 2D 等高线图。我尝试使用以下代码。
dat1 <- structure(list(x1 = c(1:10), y1 = c(10:20)), .Names = c("x1", "y1"), class = "data.frame", row.names = c(NA,-21L))
dat2 <- structure(list(x2 = c(10:20), y2 = c(20:30)), .Names = c("x2", "y2"), class = "data.frame", row.names = c(NA,-21L))
Contourcolors <- colorRampPalette(c('yellow',"red"))(20)
PointColors <- c(rep('green',5),rep('blue',5))
filled.contour(z=dat1,col=Contourcolors,
plot.axes=points( x=seq(0, 1, length.out = nrow(dat1)),
y=rep(.5,20),
col=PointColors,cex=5,pch=19)
)
Error in as.matrix.data.frame(x) :
length of 'dimnames' [2] not equal to array extent
如何使用 R 轻松做到这一点?
【问题讨论】:
-
我不确定您要达到什么目的,但
latticeplots 或ggplot2plots 在这里可能有用。 -
你的 dat1 和 dat2 只有 x 和 y 你需要一个 z 才能制作填充轮廓图。这里解释得很好stat.ethz.ch/R-manual/R-devel/library/graphics/html/…
-
我同意,请检查您的数据。