为GGPLOT2

问题描述 投票:0回答:1

I有一个包含两个变量

Type
Time
的数据框,我试图使用
Value
geom_tile
列中可视化值。当前,瓷砖是根据连续的颜色梯度进行着色的,从红色(指示高值)到白色(表明低值)。但是,我想根据其属于
Type
变量应用单独的颜色梯度。具体而言,我想为
Bb
类别使用海军到白色梯度(海军指示高值),而SSS的红色到白色梯度(红色表明高值)类别。 到目前为止,我已经尝试过的地方: Category


    

enter image description here您可以使用library(ggplot) df <- data.frame(Type = c(rep("A", 5), rep("B", 5), rep("C", 5)), Time = rep(1:5, 3), Value = round(runif(15, min = -3, max = 3), 2), Category = c(rep("BB", 5), rep("SS", 10))) ggplot(data = df, aes(x = Time, y = Type, fill = Value)) + geom_tile(height = 0.8, width = 1) + scale_fill_gradient2(limits = c(-3, 3), breaks = c(-3, 0, 3), low = "white", mid = "mistyrose", high = "#A63446", midpoint = 0, guide = guide_colorbar(frame.colour = "black", ticks.colour = "black")) + theme_bw()

软件包轻松地实现所需的结果,该软件包允许相同美学的多个尺度:
r ggplot2
1个回答
0
投票
ggnewscale


    

enter image description here

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.