nik
nik

Reputation: 2584

how can I plot several heatmaps close together?

Here is my data

data <- structure(list(name1 = structure(1:10, .Label = c("A", "B", "C", 
"D", "E", "F", "G", "H", "I", "J"), class = "factor"), value1 = c(1.251, 
-1.018, -1.074, -1.137, 1.018, 1.293, 1.022, -1.008, 1.022, 1.252
), name2 = structure(1:10, .Label = c("K", "L", "M", "N", "O", 
"P", "Q", "R", "S", "T"), class = "factor"), value2 = c(-1.005, 
1.694, -1.068, 1.396, 1.646, 1.016, 1.471, -1.609, 1.149, 1.212
), name3 = structure(c(6L, 7L, 8L, 9L, 10L, 1L, 2L, 3L, 4L, 5L
), .Label = c("AA", "AB", "AC", "AD", "AF", "V", "W", "X", "Y", 
"Z"), class = "factor"), value3 = c(1.174, -1.077, 1.274, -1.75, 
1.13, -1.018, -1.203, 1.054, 1.122, 1.151), name4 = structure(c(1L, 
3L, 2L, 5L, 4L, 8L, 6L, 7L, 9L, 10L), .Label = c("AG", "AK", 
"AN", "AY", "AZ", "BA", "BB", "BC", "BF", "BM"), class = "factor"), 
    value4 = c(1.034, 1.287, 1.205, -1.2, 2.412, 2.397, -1.054, 
    -1.063, -1.005, 1.08), name5 = structure(c(3L, 5L, 4L, 9L, 
    10L, 8L, 1L, 6L, 7L, 2L), .Label = c("DZ", "FM", "GF", "GN", 
    "GT", "LI", "NO", "RF", "TG", "TQ"), class = "factor"), value5 = c(1.339, 
    1.051, 1.368, 1.17, -1.167, -1.138, -1.031, 1.173, 1.196, 
    1.13)), .Names = c("name1", "value1", "name2", "value2", 
"name3", "value3", "name4", "value4", "name5", "value5"), class = "data.frame", row.names = c(NA, 
-10L))

i want to have 5 heatmaps side by side in order to plot one of them. I can simply do the following

ggplot(data, aes(x = 1, y = name1, fill = value1)) + 
  geom_tile() 

however, I want to be able to put all 5 of them in one figure and also change the color and bold the text of the label both X and Y

any suggestion ?

Upvotes: 0

Views: 77

Answers (2)

amrrs
amrrs

Reputation: 6325

You can use cowplot package

plot_grid()

if you want easier labeling of those plots.

require(cowplot)
plot1 <- ggplot(data, aes(x = 1, y = name1, fill = value1)) + geom_tile()
plot2 <- ggplot(data, aes(x = 1, y = name1, fill = value1)) + geom_tile()
plot_grid(plot1, plot2, align='v', labels=c('name1', 'name2'))

enter image description here

Upvotes: 1

user6376316
user6376316

Reputation:

One way I propose is to use approach given by @David LeBauer you need to install package named gridExtra

plot1<- ggplot(data, aes(x = 1, y = name1, fill = value1)) + 
  geom_tile()+
  theme(legend.position="none")

plot2<- ggplot(data, aes(x = 1, y = name2, fill = value2)) + 
  geom_tile()+
  theme(legend.position="none")

plot3<- ggplot(data, aes(x = 1, y = name3, fill = value3)) + 
  geom_tile()+
  theme(legend.position="none")

plot4<- ggplot(data, aes(x = 1, y = name4, fill = value4)) + 
  geom_tile()+
  theme(legend.position="none")

plot5<- ggplot(data, aes(x = 1, y = name5, fill = value5)) + 
  geom_tile() +
  theme(legend.position="none")

grid.arrange(plot1, plot2,plot3,plot4,plot5, ncol=5)

enter image description here

Upvotes: 3

Related Questions