代码之家  ›  专栏  ›  技术社区  ›  antecessor

注释矩形以在两个因素之间开始

  •  0
  • antecessor  · 技术社区  · 7 年前

    这是我的例子,从 这个问题 :

    ex<-data.frame(a=factor(letters[1:10]),
    b=系数(rep(c(‘b’,‘a’),5)),
    C=代表(字母[1:5],2))
    
    例如$A<-系数(例如$A,级别=Ex$A[订单(例如$B)])
    

    当格普洛丁…

    库(ggplot2)
    ggplot(数据=ex,aes(y=a,x=c))。+
    几何点()。+
    注释(xmin='b',xmax='d',ymin=-inf,ymax=inf,geom='rect',alpha=0.2)
    

    ……我们得到这个情节:

    但是,灰色矩形如何从之间开始?aandband end betweend**ande?:

    ex <- data.frame(a = factor(letters[1:10]),
                     b = factor(rep(c('b', 'a'), 5)),
                     c = rep(letters[1:5], 2))
    
    ex$a <- factor(ex$a, levels = ex$a[order(ex$b)])
    

    当G绘图时…

    library(ggplot2)
    ggplot(data = ex, aes(y = a, x = c)) +
        geom_point() +
        annotate(xmin = 'b', xmax = 'd', ymin = -Inf, ymax = Inf, geom = 'rect', alpha = 0.2)
    

    …我们得到这个情节: enter image description here

    然而,灰色矩形如何从中间开始ab结束于d**和e?

    1 回复  |  直到 7 年前
        1
  •  1
  •   pogibas    7 年前
    d e

    ggplot(ex, aes(c, a)) +
        geom_point() +
        annotate(xmin = 1.5, xmax = 4.5, 
                 ymin = -Inf, ymax = Inf, 
                 geom = "rect", alpha = 0.2)
    

    enter image description here