简体   繁体   English

如何在R图例中显示数据值的计算

[英]How to display a calculation on data values in R legend

Here's a fiddle for a simplified version of a plot I am trying to generate. 这是我要生成的绘图简化版本的小提琴。

On line 44 the plot points are sized according to 1/Error: 在第44行,绘图点的大小根据1 / Error:

main_aes = aes(x = Date, y = Popular_Support, size=1/Error)

But instead of displaying 1/Error values in the legend, I want it to display Sample Size which is 1/Error^2 , which the legend title being Sample Size . 但是,而不是显示1/Error的图例值,我希望它显示Sample Size1/Error^2 ,其中图例标题为Sample Size

I only want this displayed in the legend, but I still want the original values to weight the point sizes. 我只希望将其显示在图例中,但是我仍然希望原始值能够加权点的大小。

How can I do this? 我怎样才能做到这一点? How can I perform a calculation on the legend text that is displayed and change the legend title? 如何对显示的图例文本执行计算并更改图例标题?

You can do this as follows: 您可以按照以下步骤进行操作:

plot + scale_size_continuous(breaks=seq(40,70,10), labels=seq(40,70,10)^2,
                             name="Sample Size")

Also, plot is an R function, so it's probably better to use a different name for your plot objects. 此外, plot是R函数,因此对您的plot对象使用不同的名称可能更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM