|
1 | 1 | #' Create Histogram from dataset |
| 2 | +#' @param idata dataset from eviatlas |
| 3 | +#' @param hist_col column used for histogram |
| 4 | +#' @param axis_txt_lim character limit for label text in axis |
| 5 | +#' @keywords internal |
2 | 6 |
|
3 | | -GenTimeTrend = function(idata, hist_col, axis_txt_lim = 60){ |
| 7 | +GenTimeTrend <- function(idata, hist_col, axis_txt_lim = 60) { |
4 | 8 | UseMethod("GenTimeTrend", object = idata[hist_col][[1]]) |
5 | 9 | } |
6 | 10 |
|
7 | | -GenTimeTrend.default <- function(idata, hist_col, axis_txt_lim = 60){ |
8 | | - |
9 | | - gttmp <- ggplot2::ggplot(idata, aes_string(x = hist_col)) + |
| 11 | +#' Create Histogram from dataset - default method |
| 12 | +#' @method GenTimeTrend default |
| 13 | +#' @export |
| 14 | +#' @keywords internal |
| 15 | +GenTimeTrend.default <- function(idata, hist_col, axis_txt_lim = 60) { |
| 16 | + gttmp <- ggplot2::ggplot(idata, ggplot2::aes_string(x = hist_col)) + |
10 | 17 | ggplot2::geom_bar( |
11 | 18 | alpha = 0.9, |
12 | 19 | stat = "count", |
13 | 20 | fill = "dodger blue" |
14 | 21 | ) + |
15 | 22 | ggplot2::labs(y = "Studies") + |
16 | | - ggplot2::scale_x_discrete(name = paste(hist_col), labels = function(x) substr(x, 1, axis_txt_lim)) + |
| 23 | + ggplot2::scale_x_discrete( |
| 24 | + name = paste(hist_col), |
| 25 | + labels = function(x) substr(x, 1, axis_txt_lim) |
| 26 | + ) + |
17 | 27 | ggplot2::theme_bw() + |
18 | 28 | ggplot2::theme( |
19 | 29 | axis.line = ggplot2::element_line(colour = "black"), |
20 | 30 | panel.background = ggplot2::element_blank(), |
21 | 31 | plot.title = ggplot2::element_text(hjust = .5), |
22 | 32 | text = ggplot2::element_text(size = 13) |
23 | 33 | ) |
24 | | - |
| 34 | + |
25 | 35 | # Rotate xaxis label if too many categories |
26 | | - if (dplyr::n_distinct(idata[hist_col]) > 15){ |
| 36 | + if (dplyr::n_distinct(idata[hist_col]) > 15) { |
27 | 37 | gttmp <- gttmp + ggplot2::theme( |
28 | | - axis.text.x = element_text(angle = 40, hjust = 0.95, size = 12)) |
| 38 | + axis.text.x = ggplot2::element_text( |
| 39 | + angle = 40, |
| 40 | + hjust = 0.95, |
| 41 | + size = 12 |
| 42 | + ) |
| 43 | + ) |
29 | 44 | } |
30 | 45 | gttmp |
31 | 46 | } |
32 | 47 |
|
33 | | -GenTimeTrend.numeric <- function(idata, hist_col, axis_txt_lim = 60){ |
34 | | - |
35 | | - ggplot2::ggplot(idata, aes_string(x = hist_col)) + |
| 48 | +#' Create Histogram from dataset - numeric column |
| 49 | +#' @method GenTimeTrend numeric |
| 50 | +#' @export |
| 51 | +#' @keywords internal |
| 52 | + |
| 53 | +GenTimeTrend.numeric <- function(idata, hist_col, axis_txt_lim = 60) { |
| 54 | + ggplot2::ggplot(idata, ggplot2::aes_string(x = hist_col)) + |
36 | 55 | ggplot2::geom_bar( |
37 | 56 | alpha = 0.9, |
38 | 57 | stat = "count", |
|
0 commit comments