我正在尝试使图形附加在背景蛋白骨架上(使用geom_rect()函数绘制)。有什么方法可以创建圆角矩形而不是基本矩形(特别是红色矩形)。 这是我使用的代码。
我从grid
开始尝试了roundrectGrob()函数,但收到了错误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()
答案 0 :(得分:1)
在安装statebins
之后,按照@hrbrmstr的建议
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