Exporting tables

  • Exporting tables

     David updated 2 months, 3 weeks ago 2Members · 13 Posts
  • daisy.grewal

    Member
    October 13, 2020 at 3:48 pm

    Sorry for the newbie question, but is there a way to export nicely made tables into R Markdown (e.g. using formattable) as images, similar how you can do so with figures? I realize this isn’t an ideal thing to do, but it’s something I often end up needing to do. Thank you in advance.

  • David

    Organizer
    October 14, 2020 at 5:53 am

    Great question, Daisy! You can do this in two packages that I’m familiar with: gt and flextable. I actually did this in a package I developed for a client. Sometimes you have to go with workarounds for odd reasons!

  • daisy.grewal

    Member
    October 18, 2020 at 11:35 am

    Thank you so much!

  • daisy.grewal

    Member
    October 18, 2020 at 3:35 pm

    Hi David,

    If you see this, I’m totally stuck on a flextable question – I have a table where every row is a group. Each column shows the mean at a particular time point, and then I have a final column that’s the overall mean across all time points. Is there any way I can do conditional formatting on the row values based on the overall mean value in the final column? I’ve been stuck on this over an hour and ready to give up and do it by hand!

    Thanks for any advice,

    Daisy

  • David

    Organizer
    October 19, 2020 at 2:32 pm

    Sorry, just seeing this! Any chance we could go over it on Friday during the office hours session?

  • daisy.grewal

    Member
    October 19, 2020 at 2:37 pm

    I’ll try to make it on Friday! But I figured out a solution, not sure if there is a more elegant one: I created a column that subtracts the mean from the value I’m interested in comparing. Then I wrote a formula for color that shades the value if the column difference is > 0. Finally, I used col_keys to only display the columns with the shaded values (and not the calculated difference columns). Probably a little clumsy but it worked…

  • David

    Organizer
    October 19, 2020 at 2:39 pm

    Ok, sounds good!

  • daisy.grewal

    Member
    October 23, 2020 at 11:03 am

    Hi David,

    Sorry for changing up my question today! After my boss saw the conditional formatting I did using flextable, he decided that what he wanted was a shaded heat map instead similar to what you can do in Excel. So I switched from using flextable to formattable after seeing this website that you posted a link to in one of your blogs. The problem I’m having is that I need the shading to be according to row values, not column values. I’ve Googled endlessly on this but can’t seem to make it work. Maybe I need to switch packages again? It looks like dt table has a row-wise heatmap option, but I can’t export the end result in an image (the table needs to go into a powerpoint deck). This is the first time since using R that I’ve been tempted to just do it in Excel, but I’m hoping you might have some ideas! 🙂

    Thanks in advance,

    Daisy

  • David

    Organizer
    October 23, 2020 at 11:07 am

    No worries! It’s definitely possible. I just couldn’t remember off the top of my head. Does this tutorial by Thomas Mock help you? I believe the data_color() function from gt does what you need.

  • David

    Organizer
    October 23, 2020 at 11:13 am
  • daisy.grewal

    Member
    October 23, 2020 at 11:28 am

    Thanks David! I will check this out and see if I can get it to work using gt

  • daisy.grewal

    Member
    October 26, 2020 at 11:45 am

    Hi David,

    I picked this up again today after giving myself a mental break from it over the weekend, and I was able to get it work!! Thank you SO much for the sample code – it helped tremendously. I now have nice heatmap shading on my data, no Excel required. Best part is gt let me save it as an image. I think gt will be my go-to table package from now on.

    Daisy

  • David

    Organizer
    October 26, 2020 at 12:23 pm

    Awesome, glad to hear it!

Viewing 1 - 13 of 13 posts

Log in to reply.

Original Post
0 of 0 posts June 2018
Now