Untitled"

knitr::opts_chunk$set(echo = TRUE)
library(ggplot2)
library(dint)
dd <- data.frame(
  date = seq(date_yq(2012, 4), date_yq(2018, 4)),
  V1 = 1:25
)

ggplot(
  dd,
  aes(
    x = date,
    y = V1
  )
) + 
  geom_point() +
  scale_x_date_yq(breaks = date_yq_breaks(3)) 


ggplot(
  dd[get_year(dd$date) %in% 2014, ],
  aes(
    x = date,
    y = V1
  )
) + 
  geom_point() +
  scale_x_date_yq()

print each quarter

ggplot(
  dd[get_year(dd$date) %in% 2013, ],
  aes(
    x = date,
    y = V1
  )
) + 
  geom_point() +
  scale_x_date_yq()

ggplot(
  dd[get_year(dd$date) %in% 2013:2014, ],
  aes(
    x = date,
    y = V1
  )
) + 
  geom_point() +
  scale_x_date_yq()

scale arguments

  p <- ggplot(
    dd,
    aes(
      x = date,
      y = V1
    )
  ) + 
    geom_point() 

  p + scale_x_date_yq(labels = waiver()) + ggtitle("auto Labels")
  p + scale_x_date_yq(labels = NULL) + ggtitle("no Labels")
  p + scale_x_date_yq(breaks = date_yq(2016, 2:3), labels = LETTERS[1:2] ) + ggtitle("manual Labels")
  p + scale_x_date_yq(labels = format_yq_iso) + ggtitle("function Labels")

  p + scale_x_date_yq(breaks = waiver()) + ggtitle("auto breaks")
  p + scale_x_date_yq(breaks = NULL) + ggtitle("no breaks")
  p + scale_x_date_yq(breaks = date_yq(2016, 2:3) ) + ggtitle("manual breaks")
  p + scale_x_date_yq(breaks = date_yq_breaks(4) ) + ggtitle("function breaks")

Print every second quarter

ggplot(
  data.frame(
    date = seq(date_yq(2016, 1), date_yq(2018, 1)),
    V1 = 1:9
  ),
  aes(
    x = date,
    y = V1
  )
) + 
  geom_point() +
  scale_x_date_yq()

ggplot(
  data.frame(
    date = seq(date_yq(2016, 2), date_yq(2019, 2)),
    V1 = 1:13
  ),
  aes(
    x = date,
    y = V1
  )
) + 
  geom_point() +
  scale_x_date_yq()

ggplot(
  data.frame(
    date = seq(date_yq(2016, 3), date_yq(2019, 3)),
    V1 = 1:13
  ),
  aes(
    x = date,
    y = V1
  )
) + 
  geom_point() +
  scale_x_date_yq()

ggplot(
  data.frame(
    date = seq(date_yq(2016, 4), date_yq(2018, 4)),
    V1 = 1:9
  ),
  aes(
    x = date,
    y = V1
  )
) + 
  geom_point() +
  scale_x_date_yq()

Print long time series

ggplot(
  data.frame(
    date = seq(date_yq(2013, 2), date_yq(2018, 3)),
    V1 = 1
  ),
  aes(
    x = date,
    y = V1
  )
) + 
  geom_point() +
  scale_x_date_yq()

ggplot(
  data.frame(
    date = seq(date_yq(2013, 4), date_yq(2018, 1)),
    V1 = 1
  ),
  aes(
    x = date,
    y = V1
  )
) + 
  geom_point() +
  scale_x_date_yq()

ggplot(
  data.frame(
    date = seq(date_yq(1990, 4), date_yq(2018, 1)),
    V1 = 1
  ),
  aes(
    x = date,
    y = V1
  )
) + 
  geom_point() +
  scale_x_date_yq()


ggplot(
  data.frame(
    date = seq(date_yq(1950, 4), date_yq(2018, 1)),
    V1 = 1
  ),
  aes(
    x = date,
    y = V1
  )
) + 
  geom_point() +
  scale_x_date_yq()

date_ym

dd <- data.frame(
  date = seq(date_ym(1950, 1), date_ym(2018, 11)),
  V1 = 1
)

ggplot(
  dd,
  aes(
    x = date,
    y = V1
  )
) +
  geom_point() +
  scale_x_date_ym()



ggplot(
  dd[600:700, ],
  aes(
    x = date,
    y = V1
  )
) +
  geom_point() +
  scale_x_date_ym()


ggplot(dd[1:3, ],
  aes(
    x = date,
    y = V1
  )
) +
  geom_point() +
  scale_x_date_ym()


ggplot(dd[1:12, ],
  aes(
    x = date,
    y = V1
  )
) +
  geom_point() +
  scale_x_date_ym(breaks = date_ym_breaks(12))

ggplot(dd[1:22, ],
  aes(
    x = date,
    y = V1
  )
) +
  geom_point() +
  scale_x_date_ym(breaks = date_ym_breaks())


date_ym_breaks()(dd[1:3, ]$date)

date_ym

dd <- data.frame(
  date = seq(date_yw(1950, 1), date_yw(2018, 11)),
  V1 = 1
)

ggplot(
  dd,
  aes(
    x = date,
    y = V1
  )
) +
  geom_point() +
  scale_x_date_yw()



ggplot(
  dd[600:700, ],
  aes(
    x = date,
    y = V1
  )
) +
  geom_point() +
  scale_x_date_yw()


ggplot(dd[1:3, ],
  aes(
    x = date,
    y = V1
  )
) +
  geom_point() +
  scale_x_date_yw()


ggplot(dd[1:12, ],
  aes(
    x = date,
    y = V1
  )
) +
  geom_point() +
  scale_x_date_yw(breaks = date_yw_breaks(12))

ggplot(dd[1:22, ],
  aes(
    x = date,
    y = V1
  )
) +
  geom_point() +
  scale_x_date_yw(breaks = date_yw_breaks())

ggplot(dd[1:53, ],
  aes(
    x = date,
    y = V1
  )
) +
  geom_point() +
  scale_x_date_yw(breaks = date_yw_breaks())

ggplot(dd[1:93, ],
  aes(
    x = date,
    y = V1
  )
) +
  geom_point() +
  scale_x_date_yw(breaks = date_yw_breaks())



date_yw_breaks()(dd[1:3, ]$date)


Try the dint package in your browser

Any scripts or data that you put into this service are public.

dint documentation built on Oct. 17, 2022, 9:06 a.m.