1

I have created a grid.table object to display a dataframe in PowerBi, below there is my code:

dataset <- data.frame(BDS_ID = c("001","002"),
                  PRIORITY = c("high","medium"),
                  STATUS = c("onair","onair"),
                  COMPANY = c("airfr","fly"))
my.result <- melt(dataset, id = c("BDS_ID"))

mytheme <- ttheme_default(base_size = 10,
                          core=list(fg_params=list(hjust=0, x=0.01),
                                    bg_params=list(fill=c("white", "grey90"))))

for (i in 1:nrow(tg)) {
  tg$grobs[[i]] <- editGrob(tg$grobs[[i]], gp=gpar(fontface="bold"))
}

grid.draw(tg)

and this is my output:

enter image description here

I would like to improve my output in the following way: I would like that the row headers to be unique and have a different column for each different value of each variable repeating the column with the row headers each time.

I tried to do this using the statement t(dataset), but I do not get the desired result because the row headers are not repeated.

I would like to get an output (always classy grob) similar to this:

**PRIORITY**  high   **PRIORITY**  medium
**STATUS**    onair  **STATUS**    onair
**COMPANY**   airfr  **COMPANY**   fly

Does anyone knows how to achive this?

Thanks

user2554330
  • 37,248
  • 4
  • 43
  • 90
Lorenzo Benassi
  • 621
  • 1
  • 8
  • 31

1 Answers1

1

I'm unable to reproduce the grob format you've shown based on the code you've provided, but I've got something similar:

dataset <- data.frame(BDS_ID = c("001","002"),
                  PRIORITY = c("high","medium"),
                  STATUS = c("onair","onair"),
                  COMPANY = c("airfr","fly"))
dataset <- data.frame(t(dataset))
dataset$label1 <- rownames(dataset)
dataset$label2 <- rownames(dataset)
colnames(dataset) <- c("status1", "status2", "label1", "label2")
dataset <- dataset[c(2:nrow(dataset)), c(3, 1, 4, 2)]
rownames(dataset) <- NULL

test <- grid.draw(tableGrob(dataset))

The above code produces the following object. It doesn't look exactly like yours, but it's in the general structure you're looking for:

output Grob

Punintended
  • 727
  • 3
  • 7