Question

I want to use grid.table() in an existing plot in R. However I can't locate this table on the right side of my chart. So the thing is:

First of all, I make an histogram of my data:

hist(as.numeric(unlist((vels[counts]))),freq=F,
  col="gray",border="black",ylim=c(0,0.15),
  xlab=paste(names(vels)[counts]),
  main=paste("Weibull fitting",names(vels[counts])))

After that, I have implemented a function that plots in an existing chart the Weibull curve giving both parameters A and K:

plot_weibull(K_value,A_value)

And finally I want to place a data.frame using the grid.table() because it shows the cells in a very pretty form, and you can use italic and bold text in cells.

grid.table(round(values,3),cex=0.75,show.rownames=T,
  show.colnames=T,show.hlines=T)

The problem is that this table appears in the center of the device in front of the histogram and the curve, and I want it to be in the right side.

After all, I would like to know a tool that clicking on the graph, I would receive the area under my Weibull curve.

Was it helpful?

Solution

The hist function is base graphics and the grid.table function is grid graphics. The 2 graphics systems do not play nicely together without extra effort (as you have noticed).

The easiest fix is to use the addtable2plot function from the plotrix package rather than grid.table. It may not look the same but it would be simple.

Another option is to use a grid graphics function to create the histogram, such as something from the lattice or ggplot2 packages (both can do histograms), then create a specific viewport using grid graphics functions and use grid.table to put the table into that viewport.

Last, if you really want to mix them then see the gridBase package for ways to mix grid and base graphics.

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