0

I am using a heatmap to draw a figure in ggplot2 for different datasets. The problem is: everytime I draw a heatmap, the column width varies and thus the graphs look inconsistent next to one another.enter image description here

As you can see here, the width of the colored columns is different.

This is the code I am using:

p <- ggplot(data, aes(x=Codon,y=ID,fill=state))
q <- p + geom_raster() 

And this is sample data:

structure(list(ID = c("281154_491", "281154_491", "281154_491", 
"281154_491", "281154_491", "281154_491"), Codon = c(18L, 28L, 
79L, 81L, 84L, 86L), state = c("possible_adapted", "nonadapted", 
"nonadapted", "nonadapted", "nonadapted", "nonadapted")), .Names = 
c("ID", "Codon", "state"), row.names = c(NA, 6L), class = "data.frame")

Thanks

fmic_
  • 2,281
  • 16
  • 23
Radwa Sharaf
  • 159
  • 14
  • Can you provide a sample of the data? My guess is that you should try specifying `scale_x_continuous` and settings `breaks` and `labels` the same for each chart. – Mako212 Oct 04 '17 at 21:18
  • Thanks @Mako212 I added in a sample of the data. I tried adding scale_x_continuous(breaks=c(0,100,200,300)) but that changed the x-axis labeling only and didn't adjust the scale / width of each bar. – Radwa Sharaf Oct 04 '17 at 21:37
  • 1
    Please see [here](https://stackoverflow.com/a/5963610/4421870) for guidelines on how to create a reproducible example – Mako212 Oct 04 '17 at 21:41

1 Answers1

0

you could try to use the coord_fixed() and specifying the same ratio for all your plots:

> p <- ggplot(data, aes(x=Codon,y=ID,fill=state))
> q <- p + geom_raster() + coord_fixed(ratio = 20)
fmic_
  • 2,281
  • 16
  • 23