如何设置geom_smooth平滑的数据
这完全按预期工作:
p = qplot(year, temp, data=CETW, geom=c("point", "smooth"))
根据数据框CETW的数据绘制温度。该系列是平滑的。纯粹出于审美原因,我想为温暖的温度,正常的温度和寒冷的温度着色。有一个属性CETW $ classify,其值为“warm”,“normal”和“cold”。以下是预期颜色的数据:
p = qplot(year, temp, data=CETW, colour=classify, geom=c("point", "smooth"))
但是现在“光滑”的东西已经决定变得聪明,并且已经对三个温度中的每个温度应用了单独的平滑曲线。这很愚蠢,因为数据点太少了。那么我如何能够像第一种情况那样顺畅地讲述整个系列的温度?很高兴看到一个使用stat_smooth和method = loess的答案。
根据要求,我使用dput为CETW添加数据:
structure(list(year = 1959:2011, temp = c(4.5, 5.08, 5.73, 3.43,
1.25, 3.7, 3.8, 4.95, 5.6, 4.2, 3.2, 3.4, 4.55, 5.33, 5.2, 5.5,
6.03, 5.13, 4.23, 4.75, 2.35, 4.63, 5.35, 3.45, 4.8, 4.35, 3.2,
3.4, 3.68, 5.55, 6.75, 6.75, 4.25, 5.33, 5.2, 5.43, 5.83, 3.4,
5.13, 6.55, 5.93, 5.95, 4.65, 5.93, 5.4, 5.48, 5.73, 4.33, 6.63,
5.75, 4.4, 3.35, 4.03), classify = c("normal", "normal", "normal",
"normal", "cold", "normal", "normal", "normal", "normal", "normal",
"cold", "cold", "normal", "normal", "normal", "normal", "warm",
"normal", "normal", "normal", "cold", "normal", "normal", "normal",
"normal", "normal", "cold", "cold", "normal", "normal", "warm",
"warm", "normal", "normal", "normal", "normal", "normal", "cold",
"normal", "warm", "normal", "normal", "normal", "normal", "normal",
"normal", "normal", "normal", "warm", "normal", "normal", "cold",
"normal")), .Names = c("year", "temp", "classify"), row.names = c(NA,
-53L), class = "data.frame")
没有找到相关结果
已邀请:
2 个回复
孝铜差
在这里,您只在点图层中指定颜色美学,因此geom_smooth不考虑这一点,并且只为您提供一条线。 让我知道这个是否奏效
疮痪徘弦漏
的
参数。