Reputation: 8828
I would like to print a dataframe to a pdf file. I have tried the following:
pdf("myfile.pdf")
grid.table(df)
dev.off()
This actually works, but draws the dataframe with some cell fill colors, and other some formatting, as well as row numbers.
I just want to draw a dataframe with no specific formatting, and especially with no row numbers.
I also need to mention that I want to draw this dataframe along with a plot. (plot above the dataframe). I have tried using:
layout(matrix(c(1,2), nrow=2, byrow=TRUE), heights = c(2,1))
but the dataframe shows up on top of my plot (please see below)... I am not sure why?
Is there an easy way of doing that?
Thanks!
Upvotes: 2
Views: 5661
Reputation: 1572
You can specify where you want your data frame with viewport :
plot(NA, xlim=c(0,2), ylim=c(0,3), bty='n', xaxt='n', yaxt='n', xlab='', ylab='')
print(grid.table(df,show.rownames=F,vp=viewport(x=0.5,y=0.1)))
x and y values are relatives, x=.5,y=.1 place your data.frame in the bottom middle of your plot.
Upvotes: 5