为ggplot考虑以下数据框:
cor.mt
o variable value
o a -0.5205695
p a -0.4940820
q a -0.5997149
r a 0.4773977
s a -0.5473026
o b -0.5097157
p b -0.4837804
q b -0.5872109
r b 0.4674440
s b -0.5358914
o c -0.5385717
p c -0.5111682
q c -0.6204540
r c 0.4939069
s c -0.5662293
o d -0.5315217
p d -0.5044768
q d -0.6123321
r d 0.4874416
s d -0.5588172
o e -0.6033193
p e -0.5726213
q e -0.6950456
r e 0.5532849
s e -0.6343019
o f -0.4841113
p f -0.4594788
q f -0.5577137
r f 0.4439631
s f -0.5089722
o g -0.4900397
p g -0.4651056
q g -0.5645435
r g 0.4493998
s g -0.5152050
o h -0.5057246
p h -0.4799923
q h -0.5826129
r h 0.4637839
s h -0.5316953
o i -0.4801576
p i -0.4557263
q i -0.5531589
r i 0.4403372
s i -0.5048154
o j -0.5091269
p j -0.4832216
q j -0.5865326
r j 0.4669041
s j -0.5352724
o k -0.4979368
p k -0.4726008
q k -0.5736411
r k 0.4566419
s k -0.5235076
o l -0.5507836
p l -0.5227587
q l -0.6345226
r l 0.5051061
s l -0.5790683
o m -0.5076627
p m -0.4818319
q m -0.5848458
r m 0.4655613
s m -0.5337330
o n -0.5474711
p n -0.5196148
q n -0.6307065
r n 0.5020683
s n -0.5755857
我将使用ggplot创建一个barplot:
coul = brewer.pal(11, "RdYlBu")
coul = colorRampPalette(coul)(28)
p <- ggplot(cor.mt, aes(x=o, y=value, fill=variable)) +
geom_bar(stat="identity", position=position_dodge()) +
theme_classic() +
scale_fill_manual(values=coul) +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
输出为:https://i.stack.imgur.com/ykU61.jpg
这不是我想要的。我希望所有正值(因子r为a:n)由调色板上的14种蓝色来着色,具体取决于“变量”的值,这意味着最大的正值将是最深的蓝色,最小的正值将是最亮的蓝色
此外,对于负值(因子o,p,q和s的a:n),我希望得到相同的结果,但是要使用调色板的红色光谱。