還是這幅圖
image.png
本來以為今天的推文可以重復(fù)出來的,但還是高估自己了,實(shí)現(xiàn)過程遇到了問題酪耕,暫時(shí)還不知道如何解決,后面想到辦法再來介紹吧轨淌!
今天的推文先介紹右上角的方塊熱圖實(shí)現(xiàn)辦法吧!
首先是方塊四周的灰色邊框
這里使用到的是geom_tile()
函數(shù)迂烁。把填充設(shè)置為白色,然后把邊框線設(shè)置為灰色就可以達(dá)成這種效果
下面是一個(gè)簡單小例子
示例數(shù)據(jù)
image.png
代碼
library(readxl)
df5<-read_excel("Cor/exampledf.xlsx",
sheet = "Sheet5")
df5
library(ggplot2)
ggplot()+
geom_tile(data=df5,aes(x=x,y=y),
fill="white",color="grey")
image.png
如果是畫三角熱圖示例數(shù)據(jù)如下
image.png
這種是寬格式數(shù)據(jù)递鹉,讀取數(shù)據(jù)然后轉(zhuǎn)換為長格式
library(dplyr)
df4<-readxl::read_excel("Cor/exampledf.xlsx",
sheet = "Sheet4")
df4 %>%
reshape2::melt(id.vars="x",variable.name="y") %>%
na.omit() -> dftmp
自定義x盟步,y軸的順序,通過改變因子水平來實(shí)現(xiàn)
dftmp$x<-factor(dftmp$x,
levels = paste0("X",1:13))
dftmp$y<-factor(dftmp$y,
levels = paste0("Y",1:13))
畫圖
ggplot()+
geom_tile(data=dftmp,aes(x,y),fill="white",color="grey")+
geom_point(data=dftmp,aes(x,y,size=abs(value),color=value),
shape=15)
image.png
接下來簡單美化
ggplot()+
geom_tile(data=dftmp,aes(x,y),fill="white",color="grey")+
geom_point(data=dftmp,aes(x,y,size=abs(value),color=value),
shape=15)+
theme_minimal()+
theme(panel.grid = element_blank())+
scale_x_discrete(position = "top")+
scale_y_discrete(position = "right")+
labs(x=NULL,y=NULL)+
scale_colour_viridis_c()
image.png
除了用方塊的形狀梳虽,我們還可以使用ggstar
這個(gè)包中的其他形狀址芯,比如我們來一個(gè)心形
library(ggstar)
ggplot()+
geom_tile(data=dftmp,aes(x,y),fill="white",color="grey")+
geom_star(data=dftmp,aes(x,y,size=abs(value),fill=value),
starshape=16)+
theme_minimal()+
theme(panel.grid = element_blank())+
scale_x_discrete(position = "top")+
scale_y_discrete(position = "right")+
labs(x=NULL,y=NULL)+
scale_fill_gradient(low = "green",high = "red")
image.png
今天的次條推文還是廣告,這篇推文的示例數(shù)據(jù)和代碼會(huì)放到次條推文的留言區(qū)
歡迎大家關(guān)注我的公眾號(hào)
小明的數(shù)據(jù)分析筆記本
小明的數(shù)據(jù)分析筆記本 公眾號(hào) 主要分享:1窜觉、R語言和python做數(shù)據(jù)分析和數(shù)據(jù)可視化的簡單小例子谷炸;2、園藝植物相關(guān)轉(zhuǎn)錄組學(xué)禀挫、基因組學(xué)旬陡、群體遺傳學(xué)文獻(xiàn)閱讀筆記;3语婴、生物信息學(xué)入門學(xué)習(xí)資料及自己的學(xué)習(xí)筆記描孟!