Randomize Randomize - 1 year ago 86
R Question

R: How to create an histogram with date on x-axis and values on the y-axis?

I have a

like this:

date value
1 2012-10-02 126
2 2012-10-03 11352
3 2012-10-04 12116
4 2012-10-05 13294
5 2012-10-06 15420
6 2012-10-07 11015

How can I display an histogram that has on the x-axis the date and on the y-axis the value?

Answer Source

I think you mean a barplot since histogram doesn't need another variable as x-axis but generate the x-axis from the distribution of the value variable itself, you can specify the stat parameter as identity in this case:

ggplot(df, aes(x = as.Date(date), y = value)) + geom_bar(stat = "identity")

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download