Tag: ggplot2 grob

ggplotGrob的逆?

我有一个函数,操纵ggplot对象,通过将其转换为grob,然后修改图层。 我想这个函数返回一个ggplot对象而不是grob。 有没有一个简单的方法来将grob转换回gg? 关于ggplotGrob 的文档非常稀less。 简单的例子: P <- ggplot(iris) + geom_bar(aes(x=Species, y=Petal.Width), stat="identity") G <- ggplotGrob(P) … some manipulation to G … ## DESIRED: P2 <- inverse_of_ggplotGrob(G) such that, we can continue to use basic ggplot syntax, ie `P2 + ylab ("The Width of the Petal")` 更新: 为了回答评论中的问题,这里的动机是基于每个方面中的标签名称的值以编程方式修改方面标签的颜色。 下面的function很好地工作(根据上一个问题的洗礼input)。 我想从colorByGroup的返回值是一个ggplot对象,而不是简单的一个grob。 这是有兴趣的代码 get_grob_strips <- function(G, strips=grep(pattern="strip.*", […]