how to change the lower and upper point in this stat summary plot to 25% quartile and 75% quartile?
ggplot(data = diamonds) + stat_summary(
mapping = aes(x = cut, y = depth),
fun.ymin = min,
fun.ymax = max,
fun.y = median
)
Description. stat_summary allows for tremendous flexibilty in the specification of summary functions. The summary function can either operate on a data frame (with argument name fun. data ) or on a vector ( fun.
stat_summary() operates on unique x or y ; stat_summary_bin() operates on binned x or y . They are more flexible versions of stat_bin() : instead of just counting, they can compute any aggregate.
fun.args. A list of extra arguments to pass to fun. na.rm. If FALSE , the default, missing values are removed with a warning. If TRUE , missing values are silently removed.
ggplot(data = diamonds) + stat_summary(
mapping = aes(x = cut, y = depth),
fun.min = function(z) { quantile(z,0.25) },
fun.max = function(z) { quantile(z,0.75) },
fun = median)
Rewriting G5W's solution, using the geom function instead of the stat function:
ggplot(data = diamonds) +
geom_pointrange(mapping = aes(x = cut, y = depth),
stat = "summary",
fun.min = function(z) {quantile(z,0.25)},
fun.max = function(z) {quantile(z,0.75)},
fun = median)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With