反转并改变轴的极限 [英] Reverse and change limit of axis
问题描述
pre $
par < - ggplot(up_PAR,aes(Time.hour.of深度,z = PAR))
parplot < - par +
stat_contour(bins = 20,aes(color = .. level ..))+
scale_colour_gradient (限制= c(0.000842,0.00000000195),低=黑,高=黑)+
scale_y_reverse()+
theme_bw()+
主题(panel.grid.major =element_blank(),panel.grid.minor = element_blank())+
xlab(每日小时)+
ylab(Depth(m))+
ggtitle 下行PAR(光子/平方米/秒),1月22日)
direct.label(parplot)
但是,我想延伸深度轴以延伸0-30米。我的数据集长达175米,但我只对显示水柱顶部感兴趣。
我知道我可以使用 scale_y_continuous(limit = c(0,30))
但由于我已经扭转了我的坐标轴,并希望保持这种方式,所以我无法设置坐标轴的极限。
正如@aosmith已经指出的,只需在<$ c中使用 lim
$ c $> scale_y_reverse
library(ggplot2)
set.seed(15)$ b(b)b
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))
I am trying to create a contour plot. I would like to have depth on the Y-axis and time on the X-axis. Right now this is the code that I am using:
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)
However, I would like to extend the Depth axis to span from 0-30m. My dataset goes to 175m, but I am only interested in showing the top of the water column.
I know that I can use scale_y_continuous(limit=c(0,30))
but since I've already reversed my axis, and would like to keep it that way, I am unable to also set the limits of the axis.
As @aosmith already pointed out, just use the lim
inside the 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))
这篇关于反转并改变轴的极限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!