使用 geom_smooth 后是否有 ggplot2 函数删除原始行?
Is there a ggplot2 function to remove original lines after using geom_smooth?
我有按房屋类型细分的房屋销售时间序列数据(横轴 = 时间,纵轴 = 销售价格,每条线 = 不同的房屋类型)。它非常混乱,所以我选择在线条上使用 geom_smooth
以获得更好的可视化效果。虽然这确实会产生平滑的线条,但仍会显示凌乱的线条。我希望图表 不 显示原始数据,而只显示平滑的线条。我环顾四周,似乎无法找到一种方法来消除那些有效的旧线路。代码显示我当前所在的位置。
## sample code taken from:
library("reshape2")
library("ggplot2")
test_data <- data.frame(
var0 = 100 + c(0, cumsum(runif(49, -20, 20))),
var1 = 150 + c(0, cumsum(runif(49, -10, 10))),
date = seq(as.Date("2002-01-01"), by="1 month", length.out=100)
)
test_data_long <- melt(test_data, id="date") # convert to long format
ggplot(data=test_data_long,
aes(x=date, y=value, colour=variable)) +
geom_line() +
geom_smooth(se = FALSE)
ggplot(data=test_data_long,
aes(x=date, y=value, colour=variable)) +
# geom_line() +
geom_smooth(formula = y~x, se = FALSE)
会出现警告,但剧情应该是正确的。
我有按房屋类型细分的房屋销售时间序列数据(横轴 = 时间,纵轴 = 销售价格,每条线 = 不同的房屋类型)。它非常混乱,所以我选择在线条上使用 geom_smooth
以获得更好的可视化效果。虽然这确实会产生平滑的线条,但仍会显示凌乱的线条。我希望图表 不 显示原始数据,而只显示平滑的线条。我环顾四周,似乎无法找到一种方法来消除那些有效的旧线路。代码显示我当前所在的位置。
## sample code taken from:
library("reshape2")
library("ggplot2")
test_data <- data.frame(
var0 = 100 + c(0, cumsum(runif(49, -20, 20))),
var1 = 150 + c(0, cumsum(runif(49, -10, 10))),
date = seq(as.Date("2002-01-01"), by="1 month", length.out=100)
)
test_data_long <- melt(test_data, id="date") # convert to long format
ggplot(data=test_data_long,
aes(x=date, y=value, colour=variable)) +
geom_line() +
geom_smooth(se = FALSE)
ggplot(data=test_data_long,
aes(x=date, y=value, colour=variable)) +
# geom_line() +
geom_smooth(formula = y~x, se = FALSE)
会出现警告,但剧情应该是正确的。