Question

enter image description here

I have a data.frame in which a column has multiple lines of text. How can I wrap the text to print the data frame using grid.draw ? I tried using strwrap but no luck.

A=data.frame(name=c("ABC","XYZ","DEF"),description=c(rep("This is an example for text wrap using grid.draw in package gridExtra",3))
Était-ce utile?

La solution

Use package gridExtra which has a function grid.table, and add \n into your data frame where you want the breaks:

A=data.frame(name=c("ABC","XYZ","DEF"),description=c(rep("This is an example for text wrap \nusing grid.draw in package gridExtra",3))
grid.newpage()
grid.table(A)

You can tune up the table pretty nicely using the various arguments.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top