我正在尝试使用ggplot2 重新创建本书中的图表.我使用的数据位于帖子底部dput.它可以从出版商的网站上获得.我正在重新创建第12页的时间序列图.
这是我正在使用的代码:
y_min <- min(chartout$LCL)
y_max <- max(chartout$UCL)
ggplot() +
geom_line(mapping=aes(x=Date, y=Rate), data=chartout, size=1, alpha=0.5) +
geom_point(data = chartout, mapping=aes(x=Date,y=Rate), size=3) +
expand_limits(y = c(y_min, y_max)) +
geom_line(mapping=aes(x=Date, y=UCL), data=chartout, colour='red', size=1, alpha=0.5) +
geom_line(mapping=aes(x=Date, y=LCL), data=chartout, colour='red' , size=1, alpha=0.5) +
scale_x_date(labels = date_format("%m %d")) +
theme_bw()
Run Code Online (Sandbox Code Playgroud)
问题是我遇到了以下错误:
错误:输入无效:date_trans仅适用于Date类的对象
我已经看过这个问题,但你可以从结构中看到dputDate是一个Date格式.我知道这是因为我使用了它lubridate.
任何想法如何解决这一问题?
这里的输出输出:
chartout <- structure(list(Rate = c(0.2558, 0.2351, 0.4804, 0.2357, 0.2262,
0.0433, 0.0839, 0.0422, 0.2569, 0.1283, 0.045, 0.2418, …Run Code Online (Sandbox Code Playgroud)