I have the following wrapper function:
plot.histogram = function(x.var, y.var, pf) {
ggplot(aes_string(x.var, y.var), data = pf) +
geom_bar(stat="identity", color = "black", fill = "steelblue")
}
The function works fine. However, sometimes I don't want to pass y.var
and just use the default count
on the y-axis. Thus, in that specific case, the chart shouldn't be a bar chart but a histogram. So depending on the absence of y.var
, the function should automatically decide if it draws a bar chart or a histogram.
So, how can I make the parameter y.var
optional and automatically have a histogram drawn if y.var
is not given?