Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Sort table in descending order

Based on the data and code below, is it possible to sort the table in descending order?

Data (df):

structure(list(CITYNAME = c("a", "b", "c", 
    "d", "e", "f", "g", 
    "h", "i", "j", "k", 
    "l", "m", "n", "p", "q", 
    "r", "s", "t", "u", 
    "w", "x", "y", "z"), AvgPpt = c(127.785, 
131.456, 128.357, 114.792, 131.383, 129.696, 137.008, 136.129, 
132.881, 131.676, 129.103, 132.475, 122.263, 132.393, 134.552, 
120.322, 125.987, 132.337, 131.18, 122.705, 123.285, 128.853, 
134.494, 114.154)), row.names = c(NA, -24L), class = c("tbl_df", 
"tbl", "data.frame"))

Code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

library(ggpubr)

tbl_ppt = df %>%
             ggtexttable(cols = c("Municipilality", "Average Precipitaiton (mm)"),
                  rows = NULL,
                  theme = ttheme("mBlue"))
tbl_ppt

>Solution :

You could arrange your data in your desired order before passing it to ggtexttable:

library(ggpubr)
library(dplyr)

df %>%
  arrange(desc(AvgPpt)) %>%
  ggtexttable(cols = c("Municipilality", "Average Precipitaiton (mm)"),
              rows = NULL,
              theme = ttheme("mBlue"))

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading