12/11/2023 0 Comments Ggplot rstudio# a single fit with grouped data as asked by = dfg, aes(x = x, y = y)) + # as shown here, aes() has to be used instead of use_label(). # flexibility is needed like different separators at different positions, # use_label() makes it easier to create the mappings, but when more Ggplot(data = dfg, aes(x = x, y = y, linetype = group, grp.label = group)) + # A group label is available, for grouped data Ggplot(data = dfg, aes(x = x, y = y, colour = group)) + Labs(x = expression(italic(z)), y = expression(italic(h))) + # variable substitution as asked by same labels in equation and axes # adding a hat as asked by and = df, aes(x = x, y = y)) + Stat_poly_eq(formula = y ~ poly(x, 2, raw = TRUE), use_label("eq")) + Stat_poly_line(formula = y ~ poly(x, 2, raw = TRUE)) + # adding separate labels with equation and R2 # assembling a single label with R2, its confidence interval, and n # assembling a single label with equation, adjusted R2, F-value, n, P-value # assembling a single label with equation and R2 # using default formula, label and methods I have omitted in all code examples the additional arguments to stat_poly_line() as they are irrelevant to the question of adding labels. In the examples I use stat_poly_line() instead of stat_smooth() as it has the same defaults as stat_poly_eq() for method and formula. Although use of aes() and after_stat() remains unchanged, use_label() makes coding of mappings and assembly of labels simpler. The main change is the assembly of labels and their mapping using function use_label() added in 'ggpmisc' (=0.5.0). I have updated this answer for 'ggpmisc' (>= 0.5.0) and 'ggplot2' (>= 3.4.0) on. Each eq stat has a matching line drawing stat.) (Statistics stat_ma_eq() and stat_quant_eq() work similarly and support major axis regression and quantile regression, respectively. Statistic stat_poly_eq() in my package ggpmisc makes it possible to add text labels to plots based on a linear model fit.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |