【问题标题】:Reverse and change limit of axis轴反转和改变极限
【发布时间】:2014-09-22 13:55:53
【问题描述】:

我正在尝试创建等高线图。我想在 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)),但由于我已经反转了我的轴,并希望保持这种状态,我无法同时设置轴的限制。

【问题讨论】:

  • 为什么不只过滤.data 参数? par &lt;- ggplot(up_PAR[up_PAR$Depth &lt;= 30,], ...).
  • 看来您可以在scale_y_reverse 中设置limits。只要确保将它们按正确(相反)的顺序排列 - 我认为 scale_year_reverse(limits = c(30, 0)) 会起作用。

标签: r ggplot2 contour


【解决方案1】:

正如@aosmith 已经指出的,只需在scale_y_reverse 中使用lim

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))

【讨论】:

  • 您可以指出,魔法是通过将限制值按颠倒顺序来实现的。
猜你喜欢
  • 2015-05-11
  • 2018-03-28
  • 1970-01-01
  • 2019-01-10
  • 1970-01-01
  • 2018-04-24
  • 1970-01-01
  • 1970-01-01
  • 2012-11-27
相关资源
最近更新 更多