r - ggplot中geom_rect的roundrectGrob等价物
问题描述
我正在尝试将图形附加在背景蛋白质骨架上(使用 geom_rect() 函数绘图)。有什么方法可以创建圆边矩形而不是基本矩形(特别是红色矩形)。这是我使用的代码。
我已经尝试了 roundrectGrob() 函数,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()
解决方案
按照@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
推荐阅读
- c - MP4 到 DASH 使用 ffmpeg linux 太慢了
- c# - 运算符“<”不能应用于“方法组”和“类型”类型的操作数
- scala - 在 ScalaCheck 中使用嵌套的 forAll 在生成的对象之间共享元素
- asp.net - asmx Web 服务中的 HttpContext.Current 是 Nothing(与 C# 中的 null 相同)
- sql-server - 将 Excel 工作表转换为“XML 文档”文件类型的脚本(另存为类型“XML 电子表格 2003”)
- postgresql - RDBMS:将通常不一起查询的列放在一起是否会影响性能?
- android - navigation.xml :缺少活动,预览和链接不可用
- javascript - Chart.js 在画布上单击时获取最近的点
- google-cloud-platform - 由于 SQL 云配置无效,云运行无法启动
- java - 如何以特定格式打印素数