R语言方阵图
R语言自带datasets包中内置了euro.cross数据框,其中是11种货币的汇率矩阵,请将该数据画成方阵图,要求块内用颜色标记汇率高低、并且标注汇率(截取2位小数)
euro.cross<-round(euro.cross,2)
euro.cross %>%
as.data.frame() %>%
rownames_to_column(var="hb1") %>%
gather(key=hb2,value=hl,ATS:PTE) %>%
mutate(cor_level=cut(hl,
breaks=c(0,10,60,100,500,1000,2000,2500),right=FALSE)) %>%
ggplot(aes(x=hb1,y=hb2,fill=cor_level))+
geom_tile(color="white",size=1.5)+
geom_text(aes(label=format(hl,digits=2)))+
scale_fill_brewer(palette="YlGn",name="相关系数区间")