R/gixrd_ggplot.R

Defines functions xrd_ggplot_add_peak_pos xrd_ggplot_style

Documented in xrd_ggplot_add_peak_pos xrd_ggplot_style

#' add GIXRD style to ggplot of experimental data
#'
#' @author K. Juraic
#' @param p ggplot2 with experimental data
#' @return pp ggplot graphics (XRD difractogram)
#' @import ggplot2
#' @export
#' @examples \dontrun{xrd_ggplot_style(p)}
xrd_ggplot_style <- function(p) {
  pp <- p + theme_bw(base_size = 20) +
            xlab(expression(2*theta~'['*degree*']')) +
            ylab('Intensity [a.u.]')
  pp
}


#' add marks for XRD peak positions (tth) to gglot XRD graph
#'
#' @author K. Juraic
#' @param p ggplot XRD graph
#' @param peaks_df data.frame with column tth (xrd peaks possitions)
#' @param stick_y (y_min, y(max)) y coordinates of stick stard and end
#' @return pp ggplot graphics (XRD difractogram)
#' @export
#' @import ggplot2
#' @examples \dontrun{xrd_ggplot_add_peak_pos(p, df, c(0,100))}
xrd_ggplot_add_peak_pos <- function(p, peaks_df, stick_y = c(-100, 0)) {
  pp <- p + geom_linerange(data = peaks_df, mapping = aes_(x = ~ tth, ymin = stick_y[1], ymax = stick_y[2]))
  pp
}
kjuraic/rgixrd documentation built on June 19, 2022, 3:21 a.m.