尝试填充其他几何图形后面的区域时,为什么出现以下错误?
library(magrittr)
library(ggplot2)
library(ggstance)
#>
#> Attaching package: 'ggstance'
#> The following objects are masked from 'package:ggplot2':
#>
#> geom_errorbarh, GeomErrorbarh
my_df <- structure(list(group = structure(1:2, .Label = c("group1", "group2"),
class = "factor"), LL = c(-0.0265259354773537, 0.044689036850254),
stat = c(0.41037462410532, 0.516457204233787), UL = c(0.847275183687993,
0.988225371617319)), row.names = c(NA, -2L), .Names = c("group",
"LL", "stat", "UL"), class = c("tbl_df", "tbl", "data.frame"))
# Area to be filled in
rect1 <- data.frame(xmin = -0.2, xmax=0.45, ymin=-Inf, ymax=Inf)
以下示例有效,但我想rect1
在后面geom_pointrangeh
my_df %>%
ggplot() +
geom_pointrangeh(aes(y = group, x = stat, xmin = LL, xmax = UL,
color = group)) +
geom_rect(data=rect1,aes(xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax),
alpha=1,fill="grey70")
这是行不通的:
my_df %>%
ggplot() +
geom_rect(data=rect1,aes(xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax),
alpha=1,fill="grey70") +
geom_pointrangeh(aes(y = group, x = stat, xmin = LL, xmax = UL))
#> Error: Discrete value supplied to continuous scale
PS:第一次使用reprex包在SO上发布问题:非常好!
不要使用ggplot2
(永远,不要真的)用geom_blank()
以下方法“缩放”和“启动”缩放比例:
ggplot() +
geom_blank(data=data, aes(stat, group)) +
geom_rect(data=rect1, aes(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax),
alpha=1, fill="grey70")+
geom_pointrangeh(data=data,
aes(y = group, x = stat, xmin = LL, xmax = UL, color = group))
最好也避免将其data
用作变量名。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句