Adding lines and asterisks of statistical significance on a figure with ggplot2 (CC093)

Поделиться
HTML-код
  • Опубликовано: 21 авг 2024

Комментарии • 49

  • @Riffomonas
    @Riffomonas  3 года назад +3

    Anyone figure out the challenge I gave in the video?

    • @janarigonato
      @janarigonato 3 года назад +4

      yeap!! Do you think we can add in the paper acknowledgments the Riffomonas project for figures improvements? I am using it a lot! thank you so much

    • @adimascahyaning9202
      @adimascahyaning9202 Год назад

      Yess!!
      strip_chart +
      geom_line(data = tibble(x=c(2,3), y=c(23,23)),
      aes(x=x, y=y),
      inherit.aes = FALSE) +
      geom_line(data = tibble(x=c(2,2), y=c(22,23)),
      aes(x=x, y=y),
      inherit.aes = FALSE) +
      geom_line(data = tibble(x=c(3,3), y=c(22,23)),
      aes(x=x, y=y),
      inherit.aes = FALSE) +
      geom_line(data = tibble(x=c(1,2.5), y=c(33,33)),
      aes(x=x, y=y),
      inherit.aes = FALSE) +
      geom_line(data = tibble(x=c(1,1), y=c(32,33)),
      aes(x=x, y=y),
      inherit.aes = FALSE) +
      geom_line(data = tibble(x=c(2.5,2.5), y=c(32,33)),
      aes(x=x, y=y),
      inherit.aes = FALSE) +
      geom_text(data = tibble(x=2.5, y=24),
      aes(x=x, y=y, label = "n.s."),
      inherit.aes = FALSE) +
      geom_text(data = tibble(x=1.75, y=33.5),
      aes(x=x, y=y, label = "*"),
      size = 8,
      inherit.aes = FALSE)
      Thank you for making the video, very helpful!

    • @sergioaugusto2329
      @sergioaugusto2329 2 месяца назад

      Yeah, thank you for your learn! I wanted to show the result produced with my data, it was wonderful! :D

  • @11mgarrard
    @11mgarrard 2 года назад +6

    You are simply fantastic! I thoroughly enjoy each and every one of your videos and have applied several tips into graphics within my PhD chapters. Thank you for being such an influential resource. I hope this channel rewards you with lots of compensation and opportunity. After a while I will have to acknowledge you in the thesis. xx

    • @Riffomonas
      @Riffomonas  2 года назад

      Ah, thanks! 🤓 all the best in finishing your dissertation

  • @aelhamamy
    @aelhamamy 2 года назад +3

    Sir, I learned a lot about ggplot from you today, thanks a lot!

    • @Riffomonas
      @Riffomonas  2 года назад +1

      Wonderful Ahmad - thanks for tuning in!

  • @fburton8
    @fburton8 3 года назад +3

    I think there's a useful distinction between P

    • @r.hainez2131
      @r.hainez2131 2 года назад

      indeed, that is the difference between statistical difference and practical difference. It would be more informative to report p-value and effect size (Cohen's d, squared êta, etc.). It already done linear regression with the p value and the R² as the effect size.

  • @hanswurst4728
    @hanswurst4728 Год назад +1

    I've seen plots with these type of "significance annotations" quite often when it comes to group differences but as you pointed out they look kinda messy if you're looking at more than say four groups. I think a more eye-pleasing solution is the use of (if necessary, bootstrapped) CIs. Slap them in the backgroud with geom_errorbar() and if some group's CIs overlap, there is no statistically significant difference in means or medians or whatever you've constructed them around. Just don't use theme_minimal or void because some horizontal gridlines come in handy if you're looking at a multitude of CIs.

    • @Riffomonas
      @Riffomonas  Год назад

      Interesting idea - thanks for watching!

  • @misskana5
    @misskana5 2 года назад +1

    Thanks a lot, this video was super helpful and to the point! :)

    • @Riffomonas
      @Riffomonas  2 года назад

      Wonderful! Thanks for watching 🤓

  • @fburton8
    @fburton8 3 года назад

    These videos are really useful! The problem I'm grappling with at the moment is positioning text in a plot relative to the axes and relative to data. I would like an automated way rather than doing it manually for each plot. One case is putting significance stars (or single star! :) a fixed distance above the top bar of an errorbar (mean+-SE). Here both x and y depend on the data. The other case is placing annotations a fixed fraction up/down from the bottom/top of the plot, e.g. 5%, independent of plot size. Here the x position depends on the data, but the y position varies with the y-axis limits. I don't know if you "do requests", but if you have time to cover this in a future video I would be extremely grateful!

    • @Riffomonas
      @Riffomonas  3 года назад

      Thanks for watching and for the suggestion! I'll keep that in mind the next time I add some annotation to a figure

    • @fburton8
      @fburton8 3 года назад

      @@Riffomonas Thanks! Update: I have discovered that nudging in the y direction is a good solution to the errorbar part. Regarding the plot proportion challenge, I can get partway there using +Inf/-Inf positioning plus y nudges. The unit of the nudge looks like it's relative to the size of a character but I couldn't find where that is documented. What would be great is if the units could be set to other things too: inches, cm, normalized plot units. Initially, I 'solved' the problem by finding the actual plot limits in data units via ggplot_build() and rummaging in the resulting list, then using them to position at fixed fraction of the plot. Unfortunately, the code to do that kept breaking with ggplot2 updates. Sorry for the long reply.

    • @Riffomonas
      @Riffomonas  3 года назад

      Hey fburton8 - check out today's episode. I place the bars and stars dependent on the location of the data. ruclips.net/video/-DfCitMqdUc/видео.html

  • @songzhixing881
    @songzhixing881 Год назад

    Thank you! Very helpful!

  • @taehoonkim7819
    @taehoonkim7819 Год назад +1

    very helpful :)

    • @Riffomonas
      @Riffomonas  Год назад

      Wonderful! I'm so glad you've gotten something out of the video 🤓

  • @franklingarciafernandez5387
    @franklingarciafernandez5387 2 года назад +1

    Thanks

  • @sitendugoswami1990
    @sitendugoswami1990 3 года назад +1

    congratulations on the Oscar!

    • @Riffomonas
      @Riffomonas  3 года назад

      ha! ruclips.net/video/TK4xJlNbXLE/видео.html&lc=UgwUORClq4-zus99pol4AaABAg.9LrqhRMSMzY9LsQLzIWEo3

  • @HanySalem
    @HanySalem 10 месяцев назад

    great!

  • @christineschneider3655
    @christineschneider3655 3 года назад +2

    Hey Pat, thanks for the great video! I tried it and it worked very well. Can you maybe explain how this works with the function facet_grid? I want to add one line for all grids. This would be very helpful! :)

    • @Riffomonas
      @Riffomonas  3 года назад

      Great suggestion! I think that would require adding a column to the tibble with the variable that you are faceting on. Let me see if I can't add this to a future episode

    • @janarigonato
      @janarigonato 3 года назад +1

      @@Riffomonas Superrrr cool!!! In fact, I used your hack for inserting the bar in a boxplot, and I am struggling to do it with facet_grid!

    • @Riffomonas
      @Riffomonas  3 года назад

      Thanks again for the question! I liked it so much that I just posted a video answering it :) ruclips.net/video/ibB-MnIEUJ0/видео.html

    • @janarigonato
      @janarigonato 3 года назад

      @@Riffomonas Thanks for the quick post!! it solved my problem! at least one of them... ;)

    • @Riffomonas
      @Riffomonas  3 года назад

      @@janarigonato I'm so glad to hear it - thanks for letting me know!

  • @KN-tx7sd
    @KN-tx7sd 2 года назад +1

    Hi Pat, Thanks. If we want to do the same for multifactor grouped bar plots can you please describe how to add ANOVA significance (either as numerical values or as asterisks) like the one you showed for this plot?

    • @Riffomonas
      @Riffomonas  2 года назад

      Thanks for the question - It would be the same idea as was covered in this episode. The difference would be that instead of adding the stars and bars to a jittered plot, you would be doing it over a bar plot

    • @KN-tx7sd
      @KN-tx7sd 2 года назад

      Thanks, Pat, but in case if you have a multi-faceted plot, say more than 15 plots it might be difficult to add the stars for each plot separately. In this case, will it is recommended to use ggpubr package to add the stars e.g., using the command state_compare_means(method = "anova"). And if it is how can we add the ref.group. Thank you for your reply.

  • @PA_hunter
    @PA_hunter 2 года назад +1

    Would be interesting to see how you make this reproducible and in a way that would adjust automatically to different data :)

    • @Riffomonas
      @Riffomonas  2 года назад +1

      :) Check this out... ruclips.net/video/-DfCitMqdUc/видео.html

  • @erikacroft7056
    @erikacroft7056 2 года назад +1

    Hello great video, I am trying to be it presently but I keep an error
    Error: unexpected ',' in:
    "hypopre +
    geom_line(data= hypopre(x=c(2, 3), y=(16,"
    when I remove the ","
    Error: unexpected symbol in:
    "hypopre +
    geom_line(data= hypopre(x=c(2, 3) y"
    is it because I have categorical names as my x labels and not numerical ?

    • @Riffomonas
      @Riffomonas  2 года назад

      Hey Erika - thanks for watching! I think you're missing a c before your parentheses - geom_line(data= hypopre(x=c(2, 3), y=c(16,

  • @ieliemielio
    @ieliemielio 2 года назад +1

    Hey Pat, what do you do when the factor is significant but none of the levels differ in the pair wise tests due to the correction for multiple comparison?

    • @Riffomonas
      @Riffomonas  2 года назад +1

      I suspect the effect size would be pretty small. I’d probably say that there was an experiment wise difference but non of the pair wise comparison were significant

  • @davidalfonsoriveraruiz9077
    @davidalfonsoriveraruiz9077 Год назад

    Excelent video. Professor, I have a little problem, look at the maximum value of y in your graph (30) and the respective divisions of it (intervals of 10 units). Additionally, in your graph you have a blank space at the top that allows you to add the line to compare the categories without modifying the maximum value of y, and the division of the same. In my case, since I don't have that upper blank space, when I add the line to compare the box plots, it distorts the scale of the y axis and increases my value on the y axis. If I set the y-limits, then it removes the comparison lines from the boxplot and doesn't show them. Any ideas to fix it. I just want some extra white space at the top of the chart that allows me to insert the lines without changing my max y value.

  • @mohamedlagzouli6679
    @mohamedlagzouli6679 2 года назад +1

    Thank you so much!
    As usual, your video was useful.
    I have à little problem writing automatically normality test result (Shapiro test) onto qqplot graphic. any help please.
    thinks

    • @Riffomonas
      @Riffomonas  2 года назад +1

      You would want to convert the output to a data frame and then add it with a geom_text to geom_qqplot

    • @mohamedlagzouli6679
      @mohamedlagzouli6679 2 года назад

      ​@@Riffomonas I appreciate your note. I'll try practicing on that approach.

  • @labratatouille
    @labratatouille 3 года назад +1

    Hey Pat, this link doesn't work. www.riffomonas.org/code_club/...​.

    • @Riffomonas
      @Riffomonas  3 года назад +2

      Ack sorry! Try the new link in the description or this: riffomonas.org/code_club/2021-04-16-testing-significance