Im Anschluss an this question möchte ich eine Levelplot-Heatmap erstellen und jede Zelle entsprechend der Variablen p.value
in meinem Datenrahmen färben.Farbpalette von diskretisierten Werten für eine kontinuierliche Variable erstellen (Gitterebenenplot)
Ich möchte die Zellen in einer solchen Art und Weise gefärbt haben, dass es nur drei Farben (diskretisiert Farbpalette für kontinuierliche Variable):
weiß für p.values> 0,05
rot für p.values < 0,05 und> 0,01
dunkelrot für p.values < 0,01
Bisher ist dies mein MWE.
set.seed(150)
pv.df <- data.frame(compound=rep(LETTERS[1:8], each=3), comparison=rep(c("a/b","b/c","a/c"), 8), p.value=runif(24, 0, 0.2))
pv.df
myPanel <- function(x, y, z, ...) {
panel.levelplot(x, y, z, ...)
panel.text(x, y, round(z, 2))
}
#install.packages("latticeExtra")
library(latticeExtra)
library(RColorBrewer)
cols <- rev(colorRampPalette(brewer.pal(6, "Reds"))(10))
png(filename="test.png", height=1000, width=600)
print(
levelplot(p.value ~ comparison*compound,
pv.df,
panel = myPanel,
col.regions = cols,
colorkey = list(col = cols,
at = do.breaks(range(pv.df$p.value), 10)),
xlab = "", ylab = "", # remove axis titles
scales = list(x = list(rot = 45), # change rotation for x-axis text
cex = 0.8), # change font size for x- & y-axis text
main = list(label = "Total FAME abundance - TREATMENT",
cex = 1.5)) # change font size for plot title
)
dev.off()
Welche produziert:
Ich bin die tatsächlichen p.value
Werte in der levelplot zeigt. Es scheint ein Problem mit dem obigen Code zu geben, da "0.14" dunkler gefärbt ist als "0.08" direkt daneben.