Useful for numeric, date, and date-time scales.

breaks_width(width, offset = 0)

Arguments

width

Distance between each break. Either a number, or for date/times, a single string of the form "n unit", e.g. "1 month", "5 days". Unit can be of one "sec", "min", "hour", "day", "week", "month", "year".

offset

Use if you don't want breaks to start at zero

Examples

#> scale_x_continuous()
demo_continuous(c(0, 100), breaks = breaks_width(10))
#> scale_x_continuous(breaks = breaks_width(10))
demo_continuous(c(0, 100), breaks = breaks_width(20, -4))
#> scale_x_continuous(breaks = breaks_width(20, -4))
demo_continuous(c(0, 100), breaks = breaks_width(20, 4))
#> scale_x_continuous(breaks = breaks_width(20, 4))
# This is also useful for dates one_month <- as.POSIXct(c("2020-05-01", "2020-06-01")) demo_datetime(one_month)
#> scale_x_datetime()
demo_datetime(one_month, breaks = breaks_width("1 week"))
#> scale_x_datetime(breaks = breaks_width("1 week"))
demo_datetime(one_month, breaks = breaks_width("5 days"))
#> scale_x_datetime(breaks = breaks_width("5 days"))
# This is so useful that scale_x_datetime() has a shorthand: demo_datetime(one_month, date_breaks = "5 days")
#> scale_x_datetime(date_breaks = "5 days")