# ggplot2 绘制颜色图中色块与数值的对应关系
x = matrix(sample(24), 8)
p = ggplot(transform(expand.grid(h = 1:8, v = 1:3), z = as.vector(x)),
aes(x = h, y = v)) +
geom_tile(aes(fill = z)) +
scale_fill_distiller(palette="YlOrRd", name = "$z$") +
geom_text(aes(label = z)) +
theme_void()
print(p)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.