13.10 拟合图
plot_ly(economics,
type = "scatter",
x = ~date,
y = ~uempmed,
name = "observed unemployment",
mode = "markers+lines",
marker = list(
color = "red"
),line = list(
color = "red",
dash = "dashed"
)%>%
) add_trace(
x = ~date,
y = ~fitted(loess(uempmed ~ as.numeric(date))),
name = "fitted unemployment",
mode = "markers+lines",
marker = list(
color = "orange"
),line = list(
color = "orange"
)%>%
) layout(
title = "失业时间",
xaxis = list(
title = "日期",
showgrid = F
),yaxis = list(
title = "失业时间(周)"
),legend = list(
x = 0, y = 1, orientation = "v",
title = list(text = "")
) )
图 13.8: 拟合曲线