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:
library(ggpubr)
tbl_ppt = df %>%
ggtexttable(cols = c("Municipilality", "Average Precipitaiton (mm)"),
rows = NULL,
theme = ttheme("mBlue"))
tbl_ppt
CodePudding user response:
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"))