Arrange Table and Plot in one ggplot in R

37 views
Skip to first unread message

Volker Holzendorf

unread,
Mar 22, 2018, 8:01:15 AM3/22/18
to ggp...@googlegroups.com

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

 

Reply all
Reply to author
Forward
0 new messages