Discussion:
Arrange Table and Plot in one ggplot in R
Volker Holzendorf
2018-03-22 11:22:09 UTC
Permalink
Hi,
I want to plot an Errorbar-Plot and below the plot a table with the data of the errorbars. How can I plot the columns of the table (defined with tableGrob) directely below the categories of errorbars in the plot?
# needed packages
require(cowplot)
require(ggplot2)
require(gridExtra)

# Define the data
est<-c(1:5)
data<-data.frame(nr=est,est=est,cil=est-1,ciu=est+1)

# Plot of the data
plot<-ggplot(data,aes(x=factor(nr),y=est)) +
geom_errorbar(aes(ymin=cil,ymax=ciu),width=.1) +
geom_point(size=3,shape=15)
plot

# Table of the Data
tab<-as.data.frame(t(data))
tab <- tableGrob(tab,cols=data$nr)

# Arrange and plot Plot and Table
plot_grid(plot,tab, nrow = 2,rel_heights =c(0.75,0.25))

Thanks for any help!
Volker
--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility

To post: email ***@googlegroups.com
To unsubscribe: email ggplot2+***@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...