[英]ggplot2 - referecing summary statistics / layers
I've picked-up the ggplot2 book but I'm struggling to understand how data persists through layers. 我已经拿到了ggplot2的书,但我很难理解数据如何通过图层持续存在。
For example, lets take a dataset and calculate the mean of each X: 例如,让我们获取数据集并计算每个X的平均值:
thePlot = ggplot( myDF , aes_string( x = "IndepentVar" , y = "DependentVar" ) )
thePlot = thePlot + stat_summary( fun.y = mean , geom = "point" )
How do I "access" the summary statistics in the next layer? 如何在下一层“访问”摘要统计信息? For example, lets say I want to plot a smooth line over the dataset. 例如,假设我想在数据集上绘制一条平滑线。 This seems to work: 这似乎有效:
thePlot = thePlot + stat_smooth( aes( group = 1 ) , method = "lm" , geom = "smooth" , se = FALSE )
But lets say I want to further ignore a particular X value when generating the line? 但是,我想在生成线时想进一步忽略特定的X值? How do I reference the summarized dataset to express excluding a particular X? 如何引用汇总数据集以表示排除特定X?
More generally, how is data referenced as it flows through layers? 更一般地说,当数据流过层时如何引用数据? Am I always limited to the last statistics? 我总是限于最后的统计数据吗? Can I reference the original dataset? 我可以参考原始数据集吗?
Here is an attempt at answering your question 这是尝试回答您的问题
geom_smooth
works 这就是geom_smooth
工作的原因 data frame
and aesthetics
for each layer separately. 您可以分别为每个图层指定data frame
和aesthetics
。 For example if you want to exclude some values of x
while plotting geom_smooth
, you can specify subset = .(x != xvalues)
inside the geom_smooth
call 例如,如果要在绘制geom_smooth
排除某些x
值,可以在geom_smooth
调用中指定subset = .(x != xvalues)
I can provide more detailed examples, if you have specific questions. 如果您有具体问题,我可以提供更详细的示例。
Hope this helps 希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.