r - Moving table created by annotation_custom with geom_bar plot -


i tried searching answers couldn't find anything.

i have have plot , want add table within plot itself. can table ends being right in middle.

it possible relocate table created annotation_custom if x-axis discrete? if so, how?

thank you!

for example, want relocate table.

library(ggplot2) library(gridextra)  my.summary <- summary(chickwts$weight) my.table   <- data.frame(ids = names(my.summary), nums = as.numeric(my.summary)) ggplot(chickwts, aes(feed, weight)) +        geom_bar(stat = "identity")  +        annotation_custom(tablegrob(my.table)) 

the custom annotation in ggplot2 can rearragned inside plotting area. @ least moves them out of center. maybe solution sufficient you. i'll try , tweak this. should possible put outside plotting area well.

library(ggplot2) library(gridextra)  my.summary <- summary(chickwts$weight) my.table   <- data.frame(ids = names(my.summary), nums = as.numeric(my.summary)) ggplot(chickwts, aes(feed, weight)) +        geom_bar(stat = "identity")  +        annotation_custom(tablegrob(my.table), xmin=5,xmax=6,ymin=300,ymax=1300) 

edit:

to place table outside plot, regardless of plot consists of, grid package used:

library(ggplot2) library(gridextra) library(grid)  # data my.summary <- summary(chickwts$weight) my.table   <- data.frame(ids = names(my.summary), nums = as.numeric(my.summary))  # plot items my.tgrob <- tablegrob(my.table) plt <- ggplot(chickwts, aes(feed, weight)) +           geom_bar(stat = "identity")  # layout vp.layout <- grid.layout(nrow=1, ncol=2, heights=unit(1, "null"),   widths=unit(c(1,9), c("null","line")) )  # start drawing grid.newpage() pushviewport(viewport(layout=vp.layout, name="layout")) # plot pushviewport(viewport(layout.pos.row=1, layout.pos.col=1, name="plot")) print(plt, newpage=false) upviewport() # table pushviewport(viewport(layout.pos.row=1, layout.pos.col=2, name="table")) grid.draw(my.tgrob) upviewport()  #dev.off() 

quick png


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -