您的位置:首页 > 数据库

R工具:连接数据库,查数据,画时间序列图,加点、文本

2012-11-12 16:17 525 查看
1.channel=odbcConnect('XXXX')

2.dd=sqlQuery(channel,"select distinct CONVERT(datetime,left(scaler,10))as date,max(amount_persecond) as cles from dm.y20120630_all where node=316 group by scaler")

3.p=qplot(date, cles, data = dd, geom = c("line","smooth"),method="lm",formula=y~ns(x,8))

4.highest <- subset(dd, cles == max(cles))

5.ss=paste("峰值:",highest[2]$cles,"\n时间:",highest[1]$date,collapse="\n")

6.p+geom_point(aes(x=highest[1]$date,y=highest[2]$cles),colour="red",size=5)+geom_text(aes(highest[1]$date, highest[2]$cles, label = paste("****",ss)),hjust = 1, vjust = 1, size = 4)

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐