使用geom_smooth后是否有ggplot2函数删除原始行?

问题描述 投票:1回答:1

我有按房屋类型划分的房屋销售时间序列数据(横轴=时间,垂直轴=销售价格,每行=不同的房屋类型)。这非常混乱,因此我选择在行上使用geom_smooth以获得更好的可视化效果。尽管这确实会产生平滑的线条,但仍会显示混乱的线条。我希望图形not显示原始数据,但仅显示平滑线。我环顾四周,似乎找不到办法消除这些行之有效的老方法。该代码显示我当前所在的位置。

 ## sample code taken from: https://stackoverflow.com/questions/3777174/plotting-two-variables-as-lines-using-ggplot2-on-the-same-graph

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)
r ggplot2 smoothing
1个回答
0
投票
ggplot(data=test_data_long,
       aes(x=date, y=value, colour=variable)) +
        # geom_line() +
        geom_smooth(formula = y~x, se = FALSE)

将显示警告,但图解应正确。

© www.soinside.com 2019 - 2024. All rights reserved.