Reputation: 532
I currently have a vector of timestamps with data in the following format:
2018/03/23 2:01:59 am CET
2018/03/23 4:12:25 pm CET
2018/03/23 4:17:51 pm CET
...
I have managed to create a histogram, using the hist() function, to display the count of items every hour:
datas <- as.POSIXct(Timestamp, format="%Y/%m/%d %H:%M:%S")
hist(datas, freq=TRUE, breaks="hours", col="grey", main="Datas de Realização do Inquérito", xlab="Data", ylab="Nº de Inquéritos Realizados")
I converted the 'Timestamp' variable, which is a vector holding the same data but in factor form, to a vector of POSIXct. Then i create the histogram using that data with breaks every hour. The respective plot looks like this:
histogram plot of the timestamp vector
I was wondering how I could reproduce the exact same result but using the ggplot() function.
Upvotes: 0
Views: 915
Reputation: 18425
Without seeing your data, I haven't been able to fine-tune this, but something like this should be close to what you want...
#ggplot needs a dataframe, so...
datas <- data.frame(Data=as.POSIXct(Timestamp, format="%Y/%m/%d %H:%M:%S"))
ggplot(datas, aes(x=Data)) +
geom_histogram(binwidth=3600, fill="grey", colour="black") + #binwidth in seconds
ylab("Nº de Inquéritos Realizados") + #xlab should pick up variable name 'Data'
ggtitle("Datas de Realização do Inquérito")
Upvotes: 1