Question

How can I plot a text that wraps and covers two lines in such a way that it does not cover the next row? Here's an example:

library(gplots)

a <- data.frame(a = c(1,2,3), b = c(4,5,6))
colnames(a)[1] <- "wrap\ntext"
textplot(a)

Sample image error

It can be easily seen that the word text from the title covers the number one (1).

Was it helpful?

Solution 2

I definitely had to come back and solve this problem. I think the best solution is to insert an empty row and to delete the first row name. Of course if you want it to extend a further line, add 2 empty rows and so on

library(gplots)

a <- data.frame(a = c(1,2,3), b = c(4,5,6))
colnames(a)[1] <- "wrap\ntext"
textplot(a)

## And here is the solution

a <- rbind(c("", ""), a)  ## Insert empty row
rownames(a)<- c("", 1:(dim(a)[1]-1)) ## delete first row name and name other indices
textplot(a)

Sample image error

OTHER TIPS

play around with rmar and cmar

?textplot : rmar, cmar: Space between rows or columns, in fractions of the size of the letter 'M'.

library(gplots)

a <- data.frame(a = c(1,2,3), b = c(4,5,6))
colnames(a)[1] <- "wrap\ntext"
textplot(a, cmar = 2, rmar = 2)

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top