2

I'm plotting a line chart with ggplot2. I have a dataframe like so

hour  total
1        0  4086
2        1  3229
3        2  2134
4        3  1363
5        4   690
6        5   455

This creates my line plot:

ggplot(df, aes(hour, total)) + geom_line(color="#ff0000", size=1.5)

There are only 24 total rows (one for each hour of the day) and I'd like tick marks for every hour. When I plot this it's just 0,5,10,15 and 20:

enter image description here

What do I need to do to get tick marks on the x-axis for each hour?

lebelinoz
  • 4,890
  • 10
  • 33
  • 56
mjp92067
  • 21
  • 4
  • First you need to understand how to create a minimal reproducible example, see this [post](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Second, have you seen this [post](https://stackoverflow.com/questions/11335836/increase-number-of-axis-ticks)? In here, the solution lies in modifying `scale_x_continuous` and/or `scale_y_continuous` – mnm Aug 26 '17 at 12:53
  • 1
    Try this: `ggplot(df, aes(hour, total)) + geom_line(color="#ff0000", size=1.5) + scale_x_continuous(breaks = 0:23)` – Marco Sandri Aug 26 '17 at 12:56
  • @MarcoSandri awesome, thank you! – mjp92067 Aug 26 '17 at 13:13
  • @Ashish Thanks for the reference for a reproducible example – mjp92067 Aug 26 '17 at 13:14

0 Answers0