如何填充geom_pointrange()后面的ggplot区域?

阿吉玛


尝试填充其他几何图形后面的区域时,为什么出现以下错误?

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上发布问题:非常好!

hrbrmstr

不要使用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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何使用ggplot2为geom_pointrange()类型的图形获取图例键中的垂直线

如何使用ggplot2中的geom_pointrange()自动消除线型图例的形状和图例的线型?

带有重要性注释的ggplot2 geom_pointrange中按方面不同的颜色值

ggplot2:具有coord_flip()和自由刻度的geom_pointrange()facet_grid()

在一个图中使用geom_point和geom_pointrange时如何维护因子顺序?

R ggplot2:如何自动调整小节线后面的灰色区域

如何从后面的代码填充Repeater ItemTemplate?

如何使用geom_rect在ggplot中填充geom_line图下方的区域?

在ggplot2中绘制“ geom_smooth”时,如何删除SE上的填充区域?

在geom_pointrange中绘制每个x值的最小值,最大值,中位数

xamarin形式如何填充从后面的代码选择器

如何从后面的代码中填充anRepeater.ItemTemplate

ggplot:如何在三个不同的geom_line()下应用geom_area()或类似的填充区域而不重叠每个独立的填充?

如何在 Jetpack Compose 中使透明颜色后面的区域不可交互/不可点击?

从后面的代码填充JavaScript库

如何使用ggplot2填充图形的区域

ggplot:如何在geom_polygon中产生渐变填充

在 ggplot 如何使填充参数在 geom_dotplot() 中起作用

如何在 ggplot 混合 geom_rect 和 geom_line 中对区域进行着色?

隐藏在DIV元素后面的区域地图悬停

隐藏TabBar后无法触摸TabBar后面的区域

填充geom_violin图中的特定区域

如何在由字符串数组填充的文件s后面的代码中获取所选checbkoxlist项目的值?

如何只显示带有小平面的极地ggplot的部分绘图区域?

如何从后面的代码访问ViewModel

如何单击透明UIView后面的按钮?

如何选择元素后面的文本?

如何单击全屏 UIView 后面的按钮?

我如何模糊文本后面的背景