我正在尝试创建轮廓图。我想在Y轴上有深度,在X轴上有时间。现在,这是我正在使用的代码:
par <- ggplot(up_PAR, aes(Time.hour.of.the.day., Depth, z = PAR))
parplot <- par +
stat_contour(bins=20, aes(colour=..level..))+
scale_colour_gradient(limits=c(0.000842, 0.00000000195),low="black", high="black") +
scale_y_reverse()+
theme_bw()+
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())+
xlab("Hour of the Day")+
ylab("Depth(m)")+
ggtitle("Downwelling PAR (photons/m2/s), January 22nd")
direct.label(parplot)
但是,我想将“深度”轴扩展为0-30m。我的数据集达到175m,但我只想显示水柱的顶部。
我知道我可以使用
scale_y_continuous(limit=c(0,30))
,但是由于我已经反转了轴,并希望保持这种方式,所以我也无法设置轴的限制。 最佳答案
正如@aosmith指出的那样,只需在lim
中使用scale_y_reverse
library(ggplot2)
set.seed(15)
ggplot(data.frame(x=sort(runif(20, 0, 20)), y=cumsum(runif(20,0 ,2))), aes(x,y)) +
geom_point() +
scale_y_reverse( lim=c(10,0))