简体   繁体   中英

roundrectGrob equivalent for geom_rect in ggplot

I am trying to make the graph appending on a background protein backbone (drawing using geom_rect() function). is there any way to create the round-edged rectangle instead of the basic rectangle (specifically for the red rectangle). Here is the code I have used.

I have tried the roundrectGrob() function from grid but getting the error 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()

蛋白质pfam结构图

Following the suggestion of @hrbrmstr, after installing statebins with

devtools::install_github("hrbrmstr/statebins")

try this

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

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM