2016-08-11 31 views
0

这里是我的数据我怎样才能将几个贴图贴在一起?

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)) 

我想有并排 5热图侧,以绘制其中之一。我可以简单地做以下

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

不过,我希望能够把他们的所有5个在一幅图 ,改变它的标签,X和Y

的色彩和大胆的文字任何建议?我建议

回答

4

一种方法是 你需要安装一个名为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

1

包您可以使用cowplot包使用由@大卫LeBauer给出的方法

plot_grid()

如果你想更容易标记这些情节。

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

相关问题