#' Payment Box Plot
#'
#' This function produces a box plot of payments by DRG code.
#'
#' @param df a dataframe of data from Centers for Medicare & Medical Services.
#' This dataframe must contain DRG codes and payments data. And the column
#' names of these variables should be "DRG.Definition", "Average.Covered.Charges", "Average.Total.Payments" and "Average.Medicare.Payments".
#' @param payment a character string specifying the type of \code{payment}, must be one of "Average.Covered.Charges", "Average.Total.Payments" or "Average.Medicare.Payments".
#'
#' @return A box plot of payments by DRG Codes.
#' @export
#'
#' @importFrom ggplot2
#' @importFrom dplyr
#'
#' @examples
#' data(sample_data)
#'
#' payment_boxplot(drg_data,"Average.Covered.Charges")
#'
payment_boxplot <- function(df, payment){
df %>%
mutate(drg_code = substr(DRG.Definition,1,3)) %>%
ggplot(aes(y = drg_code,
x = get(payment),
group = drg_code,
fill = drg_code)) +
geom_boxplot() +
theme(legend.position = 'none') +
labs(title = paste('Box Plot of',
all_of(chartr('.', ' ', payment)),
'by DRG Code'),
x = all_of(chartr('.', ' ', payment)),
y = 'DRG Codes')
}
## datafram of drg and statistics.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.