I have a function for creating plots in R. I wish to print the unit along with feature name. Below is the code.
library(ggplot2)
plotfunction <- function(feature, featur_name, feature_unit){
ggplot(aes(x = feature), data = mtcars) +
geom_histogram(binwidth = 0.5) +
labs(x = paste(featur_name, feature_unit), y = "Count, #")
}
plotfunction(mtcars$wt, "Displacement, ", expression({g}/{dm}^{3}))
The function produces the plot as as shown below.