Output text block and qplot in the same pdf or png format in r

I have a histogram created using a graph in the ggplot2 package:

enter image description here

and a table created using a text block from the gplots package

enter image description here

I would like to show them in the same pdf or png format, if possible.

I tried grid.arrange with no luck. Any other suggestions? Since each table is only 5 rows, I also considered the possibility of inserting it into the plot as a "legend" or a text field on the qplot border. Any tips on how to do this well? Thanks for your ideas.

DECISION ##

In the end, I went and inserted, unfortunately, my color scheme looks worse ... I posted this issue as a new question.

enter image description here

+5
source share
2 answers

,

library(ggplot2)
library(gridExtra)

g = tableGrob(iris[1:2, 1:2])

p = qplot(1:10, 1:10, geom = "blank") +
     annotation_custom(g) # as inset

grid.arrange(p, g, ncol=1) # stacked
ggsave("plot-table.pdf", arrangeGrob(p, g, ncol=1))
+8

gridExtra

my_hist<-ggplot(diamonds, aes(clarity, fill=cut)) + geom_bar()  
my_table<- tableGrob(head(diamonds)[,1:3],gpar.coretext = gpar(fontsize=8),gpar.coltext=gpar(fontsize=8), gpar.rowtext=gpar(fontsize=8))  
pdf("myplot.pdf")  
grid.arrange(my_hist,my_table, ncol=2)  
dev.off()

pdf: pdf ( "myplot.pdf", width = 10, height = 6)
, :
blankPanel < -grid.rect(GP = gpar (Col = "" )) enter image description here

+7

All Articles