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

ggplot中几何矩形的roundrectGrob等价物

  •  0
  • shams  · 技术社区  · 6 年前

    这是我用过的代码。

    grid 但是得到了错误 Error: Don't know how to add roundrectGrob(x = 28, y = -2.3, width = 22, height = 0.45) to a plot

    library(ggplot2)
    p <- ggplot() +
    ylim(-4, 4) +
    xlim(0, 100)
    ## First rect
    p <- p + geom_rect(mapping=aes(xmin=10,
    xmax=90,
    ymin=-2.15,
    ymax=-2.00),
    colour = "black",
    fill = "grey")
    ## Second rect
    p <- p + geom_rect(mapping=aes(xmin=28,
    xmax=50,
    ymin=-2.30,
    ymax=-1.85),
    colour = "black",
    fill = "red")
    # print
    p
    dev.off()
    

    Protein pfam structure for plot

    1 回复  |  直到 6 年前
        1
  •  2
  •   Marco Sandri    6 年前

    按照@hrbrmstr的建议,安装后 statebins

    devtools::install_github("hrbrmstr/statebins")
    

    试试这个

    library(ggplot2)
    p <- ggplot() + ylim(-4, 4) + xlim(0, 100)
    ## First rect
    p <- p + geom_rect(mapping=aes(xmin=10,
             xmax=90, ymin=-2.15,  ymax=-2.00),
             colour = "black", fill = "grey")
    ## Second rect
    p <- p + statebins:::geom_rrect(mapping=aes(xmin=28, 
             xmax=50, ymin=-2.30, ymax=-1.85),  
             colour = "black", fill = "red")
    # Print
    p
    

    enter image description here