## Open a connection con <- dbConnect(drv, host="192.168.0.119", port="5432", user="postgres", password="hackfest", dbname="superstars") #consulta no banco para um artista q <- dbGetQuery(con, "SELECT created, count(*) FROM tweets WHERE artist='suricato' GROUP BY created ORDER BY created") jan1 <- strptime('2014-01-01', "%Y-%m-%d") q$week <- as.integer(difftime(strptime(q$created, "%Y-%m-%d"), jan1, unit="week")) #após isso é possível que tenha algum NA na coluna week, porém é simples de arrumar e não interfere muito no resultado. q$created <- NULL a <- aggregate(count ~ week, q, sum) plot(a, type="o", col="red")