1
以下是我嘗試使用ggplot2
創建熱圖。在ggplot中分組標籤
#DATA
set.seed(42)
df1 = data.frame(ID = paste0("I", 1:40),
group = rep(c("Dry", "Rain"), each = 20),
subgroup = rep(paste0("S", 1:4), each = 10),
setNames(data.frame(replicate(8, rnorm(40))), letters[1:8]))
library(reshape2)
df1 = melt(df1, id.vars = c("ID", "group", "subgroup"))
df1 = df1[order(df1$group, df1$subgroup),]
df1$fact = paste(df1$subgroup, df1$ID)
df1$fact = factor(df1$fact, levels = unique(df1$fact))
#PLOT
library(ggplot2)
ggplot(df1, aes(x = variable, y = fact, fill = value)) +
geom_tile() +
scale_y_discrete(labels = df1$subgroup[!duplicated(df1$ID)])
情節正是我想除了一個事實,那是什麼標籤S1
,S2
,S3
,並且S4
反覆各做10次。有沒有辦法只顯示它們一次,然後在S1
,S2
,S3
和S4
之間加上某種中斷。
我也很好奇,如果有辦法把group
到subgroup
左側中的情節作爲輔助y軸但這是可選的。