【问题标题】:roundrectGrob equivalent for geom_rect in ggplotggplot中geom_rect的roundrectGrob等价物
【发布时间】:2018-10-15 16:10:10
【问题描述】:

我正在尝试将图形附加在背景蛋白质骨架上(使用 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()

【问题讨论】:

  • 已经试过了。但是得到了这个错误。 p + geom_rrect(mapping=aes(xmin=28, + xmax=50, + ymin=-2.30, + ymax=-1.85), + color = "black", + fill = "red") geom_rrect 中的错误(mapping = aes(xmin = 28, xmax = 50, ymin = -2.3, ymax = -1.85), : 找不到函数“geom_rrect”。
  • 我(懒惰地)暗示你可以将源代码复制到你的会话中???

标签: r ggplot2


【解决方案1】:

按照@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

【讨论】:

  • 如果有助于正确导出此文件,我可以进行更改并推送到 CRAN。这只是意味着我必须记录函数,而我之前太懒了
猜你喜欢
  • 2019-11-03
  • 1970-01-01
  • 2020-10-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多