KOF-ch / tstools

A time series toolbox for official statistics
11 stars 4 forks source link

getGlobalXInfo truncates to nearest quarter #264

Open HomoCodens opened 6 years ago

HomoCodens commented 6 years ago

When trying to get exact plots of windows that start/end at any month that is more annoying than useful.

HomoCodens commented 5 years ago

This also leads to problems with the KOF Monatsblätter. Example:

x <- generate_random_ts(3, starts = 2018 + 6/12, lengths = 5)

tt <- init_tsplot_theme(
  fill_year_with_nas = FALSE,
  show_x_axis = FALSE,
  use_bar_gap_in_groups = FALSE
)

tsplot(x, left_as_bar = TRUE, group_bar_chart = TRUE, theme = tt)

usr_coords <- par("usr")
axis(
  1,
  seq(usr_coords[1], usr_coords[2], length.out = 6),
  hadj = -0.5,
  padj = -0.9
)

Here the bar groups should be evenly spaces across the whole plot to correspond with the manually drawn ticks. The example below makes it clear, that tsplot draws an additional empty month to fill the quarter:

x <- generate_random_ts(3, starts = 2018 + 6/12, lengths = 5)

tt2 <- init_tsplot_theme(
  fill_year_with_nas = FALSE,
  use_bar_gap_in_groups = FALSE
)

tsplot(x, left_as_bar = TRUE, group_bar_chart = TRUE, theme = tt2)
HomoCodens commented 5 years ago

I guess this can be worked around with manual_ticks_x:

x <- generate_random_ts(3, starts = 2018 + 6/12, lengths = 5)

tt <- init_tsplot_theme(
  fill_year_with_nas = FALSE,
  use_bar_gap_in_groups = FALSE,
  show_x_axis = FALSE
)

bla <- tsp(x$ts1)

tsplot(x,
      left_as_bar = TRUE,
      group_bar_chart = TRUE,
      theme = tt,
      manual_ticks_x = seq(bla[1], bla[2] + 1/bla[3], by = 1/bla[3]))

usr_coords <- par("usr")
axis(
  1,
  seq(usr_coords[1], usr_coords[2], length.out = 6),
  c("Jul", "Aug", "Sept", "Okt", "Nof", ""),
  hadj = -0.5,
  padj = -0.9
)