在R ggplot2中将gtable转换为ggplot [英] Convert gtable into ggplot in R ggplot2

查看:56
本文介绍了在R ggplot2中将gtable转换为ggplot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尽管可以使用 ggplotify :: as.ggplot 将gtable转换为ggplot,但输出与原始ggplot不同.例如:

Although gtable could be converted into ggplot using ggplotify::as.ggplot, the output is different from the origin ggplot. For example:

library(ggplot2)
p <- ggplot(mtcars, aes(wt, mpg)) + geom_point()
g <- ggplot_gtable(ggplot_build(p))
p_new <- ggplotify::as.ggplot(p)

# origin
p + theme(aspect.ratio = 2)

# changed
p_new + theme(aspect.ratio = 2)   # different figure shape from the origin one

我怎样才能将gtable隐瞒到相同 ggplot p_new 作为源一个 p ?

How could I covert gtable into the same ggplot p_new as the origin one p?

推荐答案

您可以使用 ggplotify :: as.ggplot():

library("ggplotify")
as.ggplot(q)

这篇关于在R ggplot2中将gtable转换为ggplot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆