Learn R Programming

glioblastomaEHRsData (version 1.1.0)

plotMunich2019dataset: Plot variables from the munich2019dataset

Description

This function creates a plot of one or two variables from the 'munich2019dataset' dataframe. It automatically chooses the appropriate plot type based on the variable types. It can export and save the plot by specifying the directory, filename and extension. Provided variable names need to be in the dataset, otherwise an error will be launched. The function makes it easy to plot univariate and bivariate plots while offering a quick way to save and export them.

Usage

plotMunich2019dataset(name1, name2 = NA, savePath = NA)

Value

A 'ggplot2' object representing the generated plot. If the specified variables are not found in the dataset, returns a warning.

Arguments

name1

Character. The name of the first variable to plot.

name2

Character (optional). The name of the second variable for bivariate plots. Default is NA.

savePath

Character (optional). File path where the plot should be saved. Default is NULL which means no plot will be saved. To save a plot using all the default options put an empty string. The format must be: 'filepath/filename.extension' where:

  • filepath is the directory (must already exist), default is the working directory;

  • filename is the name of the file, default to 'plot_munich2019dataset_var1_var2_timestamp.png';

  • extension must be one of the supported 'ggsave' extensions and must be specified, unless using the default file name.

Details

The function supports the following plotting logic:

  • If only 'name1' is provided:

    • Numeric/integer variable → Histogram.

    • Character/factor variable → Bar plot.

  • If both 'name1' and 'name2' are provided:

    • One numeric/integer and one categorical → Boxplot.

    • Both categorical → Grouped bar plot.

See Also

DataExplorer::plot_bar(), DataExplorer::plot_histogram(), DataExplorer::plot_boxplot, savePlot()

Examples

Run this code
# Univariate plot without saving
plotMunich2019dataset("age_years")

# Bivariate plot without saving
plotMunich2019dataset("cHsp70_low0_high1", "sex_male0_female1")

# \donttest{
# Bivariate plot saved in the path directory with the chosen name and extension
plotMunich2019dataset("age_years", "sex_male0_female1", savePath = NA)

# Univariate plot saved in the working directory with the chosen name and extension
plotMunich2019dataset("sex_male0_female1", savePath = NA)

# Univariate plot saved in the path directory with default name and extension
plotMunich2019dataset("MGMTmethylation_methylated1_unmethylated0", savePath = NA)
# }

Run the code above in your browser using DataLab