这是我的数据
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的文本
任何建议?
答案 0 :(得分:3)
我建议的一种方法是使用@David LeBauer给出的方法 您需要安装名为 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)
答案 1 :(得分:1)
您可以使用cowplot包
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'))