0

I can make this stacked barchart with data table in Excel.

stacked barchart with data table: enter image description here

I can make the barchart in R

library(ggplot2)
specie <- c(rep("sorgho" , 4) , rep("poacee" , 4) , rep("banana" , 4) , rep("triticum" , 4) )
condition <- rep(c("big", "really big", "huge", "tiny"))
value <- abs(rnorm(16 , 0 , 15))
data <- data.frame(specie,condition,value)
cbPalette <- c("#798320","#c0cf3a", "#0276c3", "#025b97")
ggplot(data, aes(fill=condition, y=value, x=specie)) + 
  geom_bar(position="stack", stat="identity") + ggtitle("title") +  scale_fill_manual(values=cbPalette)

stacked barchart in R: enter image description here

But I can't seem to find any way to make the data table be part of the barchart.

I can make a separate table and fiddle with it to get it to align to the X-axis of the graph but that seems clunky.

Any ideas?

Behnam Hedayat
  • 837
  • 4
  • 18
  • 1
    To my knowledge, there's not a *great* way to do this - it's always finicky with the current solutions - but there are a number of solutions, Suggested duplicates: [Adding a table of values below the graph](https://stackoverflow.com/q/41164675/903061), [Adding a table within the plotting region](https://stackoverflow.com/a/51502623/903061) (could probably be easily adapted for below the plotting region), [How to add table in ggplot grid](https://stackoverflow.com/q/65347604/903061), ... – Gregor Thomas May 28 '21 at 17:00
  • 1
    [Add table corresponding to y-axis outside the plot](https://stackoverflow.com/q/56640426/903061) - this one has the sort of axis alignment you're looking for and is probably the best match. – Gregor Thomas May 28 '21 at 17:00

0 Answers0