How to position text in the intermediate columns?

Asked

Viewed 91 times

6

Hello, I generated a column chart that is composed of 15 groups of 3 columns (each group of 3 refers to a patient in 3 distinct times) and would like to identify each patient by placing a text aligned to each column of the medium (in each group of 3).

Follow the code I used so far:

ord_interleave_elements <- order(c(seq_along(chemo_dataset$blast_percent), seq_along(chemo_dataset$d15_absol), seq_along(chemo_dataset$d29_absol)))
barplot(unlist(c(chemo_dataset$blast_percent, chemo_dataset$d15_absol, chemo_dataset$d29_absol))[ord_interleave_elements], beside = TRUE, col = c("black", "grey", "lightgrey"), ylab = "Leukemic cell (%) in bone marrow", xlab = "Case number", family = windowsFont("times"))

How can I position patient identification for each group of 3?

1 answer

8


To achieve this, you just need to know that you can use the object itself barplot for the positions of x in function text. I already gave a similar answer on this one.

Since your code is not reproducible, I created some data (with fewer groups to be clearer) to demonstrate an example.

Since you want one name per group, we have to create labels empty for the first and third bar of each group, and also remember to repeat the values of y three times, once per group bar.

You did not say where you want the name, so I did the hardest, which is to put up. If you want down, just put y = 0 and pos = 1, or something like.

set.seed(42)
dados <- replicate(5, runif(3))
bp <- barplot(dados, beside = TRUE, ylim = c(0, 1), main = "Grupos")
labs <- unlist(lapply(1:5, function(i) c("", paste("Grupo", i), "")))
text(x = bp, y = rep(apply(dados, 2, max), each = 3), labels = labs, pos = 3)

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.