ggplot2 yol bu deneyin: Sen scale_fill_XXX
kullanabilirsiniz
x <- seq(-10, 10, 0.1)
df <- data.frame(x, y1 = pnorm(x), y2 = pnorm(x) * 2)
df$t <- df$y2 - df$y1
dfm <- melt(df, id = "x")
ggplot(NULL, aes(x, value)) +
geom_line(aes(colour = variable),
droplevels(subset(dfm, variable %in% c("y1", "y2")))) +
geom_rect(aes(xmin = x - 0.05, xmax = x + 0.05, ymin = -0.5, ymax = -0.4, fill = value),
subset(dfm, variable == "t"))
GÜNCELLEME. İşte bir jet renkli versiyonu:
jet.colors <- colorRampPalette(c("#00007F", "blue", "#007FFF", "cyan","#7FFF7F", "yellow", "#FF7F00", "red", "#7F0000"))
# panel on the left side
p <- ggplot(NULL, aes(x, value)) +
geom_line(aes(colour = variable),
droplevels(subset(dfm, variable %in% c("y1", "y2")))) +
geom_rect(aes(xmin = x - 0.05, xmax = x + 0.05, ymin = -0.5, ymax = -0.4, fill = value),
subset(dfm, variable == "t")) +
scale_fill_gradientn(colours = jet.colors(7))
p
ve ggplot2 sonraki sürümünde
, sen efsane olarak Colorbar kullanabilirsiniz.
# panel on the right side
p + guides(fill = "colourbar")
Tekrarlanabilir örnek gönderebilir misiniz? –