如何在ggplot2中通过任意因子加权平滑?

时间:2012-12-16 19:34:42

标签: r ggplot2

以下是相关示例。我正在考虑将球员效率作为NBA球员距离的函数。我想通过在每个距离拍摄的照片量(即气泡的大小)来对平滑进行加权。有没有办法做到这一点?生成此图的命令是:

ggplot(top10,aes(x=FT,y=PPS,size=FGA,color=PPS))
+scale_x_continuous(limits = c(0, 30))
+scale_y_continuous(limits = c(0, 2.2))+geom_point()
+facet_grid(NAME~.,space="free")
+stat_smooth(color="darkblue",size=2)

enter image description here

2 个答案:

答案 0 :(得分:13)

如上所述,如果您将第一行更改为

ggplot(top10,aes(x=FT,y=PPS,size=FGA,color=PPS,weight=FGA))

它有效。

以下是更正后的版本:

enter image description here

答案 1 :(得分:0)

要具有多条平滑线时,可以分别在每个图形中进行加权:

ggplot(top10,aes(x=FT,y=PPS,size=FGA,color=PPS))
+scale_x_continuous(limits = c(0, 30))
+scale_y_continuous(limits = c(0, 2.2))+geom_point()
+facet_grid(NAME~.,space="free")
+stat_smooth(color="darkblue",size=2, aes(weight= FGA))
相关问题