gpt4 book ai didi

r - 如何使用 ggplot 函数制作连续平滑的中位数?

转载 作者:行者123 更新时间:2023-12-04 09:42:32 25 4
gpt4 key购买 nike

这是我的代码:

ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(cyl)))+
geom_point(stat = "identity")+
theme_bw()+
geom_smooth()

我得到的不是连续平滑的中位数,而是整个数据的中位数看起来支离 splinter 且不准确。我认为这是由于“factor(cyl)”函数所致。

这是我的代码给出的链接:

diagram of output

最佳答案

如果在 geom_smooth() 中添加 aes(group=1) 您将解决您的问题:

ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(cyl)))+
geom_point(stat = "identity")+
theme_bw()+
geom_smooth(aes(group=1))

关于r - 如何使用 ggplot 函数制作连续平滑的中位数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31996599/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com