【发布时间】:2019-02-21 15:31:53
【问题描述】:
当将转换应用于 y 轴时,如果想要将 geom_rect 应用于 ggplot 对象的 y 轴上的 Infinity,是否有解决方法?
除非您注释掉 scale_y_continuous 线,否则下面的代码不会绘制间隔矩形。使用转换后的比例时,我必须输入实际数据限制。我可能会编写一个函数来查找正在绘制的其他数据的最小值/最大值以避免硬编码值,但我正在寻找更接近 Inf 方法的东西。我尝试使用 NA 而不是 Inf 但没有运气。
library(tidyverse)
data(economics)
ints<-data.frame(start=as.Date(paste0(seq(1970,2020,by=10),"-01-01"))) %>%
mutate(end=start+1785)
plt<-ggplot(economics,aes(date,unemploy)) + theme_bw() +
scale_y_continuous(trans="sqrt") +
geom_rect(data=ints,inherit.aes=F,aes(xmin=start,xmax=end,ymin=-Inf,ymax=Inf)) + geom_line()
plt
【问题讨论】:
-
因为你不能取负数的平方根,所以它不能处理
ymin =-Inf。为什么不直接设置ymin=0?