如何使用ggplot2绘制filled.contour图?

时间:2017-09-21 19:09:43

标签: r plot ggplot2 legend

我有一些数据,我尝试了一个filled.contour情节,看起来不错。但是,传说很难控制,所以我想使用ggplo2。但我不知道如何使用filled.contour绘制ggplot2

数据包含840行(代表日期)和12列(代表12个时间刻度)。这是一个例子

set.seed(66)
Mydata <- sample(x=(-3:3),size = 840*12,replace = T)
Mydata <- matrix(data=Mydata,nrow=840,ncol=12)
Dates <- seq(from=1948+1/24, to= 2018,by=1/12)
data.breaks <- c(-3.5,-2.5,-1.5,0,1.5,2.5,3.5)
filled.contour(Dates,seq(1:12),Mydata,col=cols(11),xlab="",ylab="time-scale",levels=data.breaks)

enter image description here

正如我们所看到的,传奇间隔不是我想要的。我想在图例上显示-3.5,-2.5,-1.5,0,1.5,2.5,3.5,我相信使用ggplot2更容易做到这一点。谢谢你的帮助。

1 个答案:

答案 0 :(得分:4)

ggplot2的{​​{1}}替代filled.contour

stat_contour

enter image description here