Posizionare tavoli griglia in r
Domanda
Voglio usare grid.table () in una trama esistente in R. Tuttavia non posso individuare questa tabella sul lato destro del mio grafico.Quindi la cosa è:
Prima di tutto, faccio un istogramma dei miei dati:
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])))
.
Successivamente, ho implementato una funzione che traccia in un grafico esistente, la curva di weibull fornisce entrambi i parametri A e K:
plot_weibull(K_value,A_value)
.
E infine voglio posizionare un dato. Frame usando la griglia.table () perché mostra le cellule in una forma molto carina e puoi usare il testo in corsivo e grassetto nelle cellule.
grid.table(round(values,3),cex=0.75,show.rownames=T,
show.colnames=T,show.hlines=T)
.
Il problema è che questa tabella appare al centro del dispositivo davanti all'istogramma e alla curva, e voglio che sia nel lato destro.
Dopo tutto, vorrei conoscere uno strumento che clicca sul grafico, riceverei l'area sotto la mia curva di weibull.
Soluzione
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.