rr-markdownanovatukey

R function for displaying results of aov() and tukeyHSD() in R markdown in professional way


I have some data that's unfortunately PHI and I can't share (to make reproducible) but I'd like to display it in a PDF document from R markdown.

Currently my results will display, but they don't look great, i.e.: enter image description here enter image description here

I'd love to display the exact same numbers, but just "prettier". No "##" along the side, and just a nice table in R markdown

I've obviously googled it, and I ran across sites such as this one or this one

But there seems to be drawbacks to using many of these methods. Either it uses a different code to initially conduct the anova (I used aov(), some of these sites use lm() and it doesn't seem to work with aov() ), or it doesn't help with the Tukey results.... or when I load the package it hides an important function I need in a different package (library(papeR) masks summarise, and summarize from dplyr() ).

Is there a simply way I'm missing in order to display those results 'cleanly'?


Solution

  • I don't know how professionals format these things, but I think, the nicest solution is broom + any table package.

    For example:

    ```{r warning = FALSE, echo = FALSE, message=FALSE}
    library(broom)
    library(flextable)
    
    fm1 <- aov(breaks ~ wool + tension, data = warpbreaks)
    thsd <- TukeyHSD(fm1, "tension", ordered = TRUE)
    xx <- tidy(thsd)
    
    flextable(xx)
    ```
    

    enter image description here

    Looks nice, I think.