从ggplot对象提取输入数据 [英] extract input data from ggplot object

查看:130
本文介绍了从ggplot对象提取输入数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以使用

提取ggplot2图中的数据

I know I can extract the data I plot in a ggplot2 plot using

p <- ggplot(df, aes(x, y)) + geom_point()
ggplot_build(p)$data

但是在这种情况下,data是正在绘制的数据.有什么方法可以获取输入数据-在这种情况下为df-

But data in this case is the data being plotted. Is there any way of getting the input data -- df in this case -- back?

推荐答案

p本身是list,您可以使用p$data获得df.

p itself is a list, you can get df with p$data.

一个例子:

library(ggplot2)
p <- ggplot(mtcars, aes(x = mpg, y = cyl)) + geom_point()
identical(p$data, mtcars)
# [1] TRUE

这篇关于从ggplot对象提取输入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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