我在 Excel 中有热图,我试图在 R 中重新创建它。它的基本数据用于 RFM 分段,在 Excel 中,颜色范围很棒,但我很难在 R 中获得如此漂亮的平滑颜色渐变,并尝试了多种方法,但无法实现相同的平滑渐变。
我的 Excel 热图如下所示:
我的 R 热图如下所示:
我的 R 代码是:
cols <- brewer.pal(9, 'RdYlGn')
ggplot(xxx)+
geom_tile(aes(x= mon, y = reorder(freq, desc(freq)), fill = n)) +
facet_grid(rec~.) +
# geom_text(aes(label=n)) +
# scale_fill_gradient2(midpoint = (max(xxx$n)/2), low = "red", mid =
"yellow", high = "darkgreen") +
# scale_fill_gradient(low = "red", high = "blue") +
scale_fill_gradientn(colours = cols) +
# scale_fill_brewer() +
labs(x = "monetary", y= "frequency") +
scale_x_discrete(expand = c(0,0)) +
scale_y_discrete(expand …Run Code Online (Sandbox Code Playgroud)