我正嘗試使用ggplot生成相關矩陣的熱圖,但不在數據中包含前導零。從ggplot2圖中刪除前導零
考慮在「數據集」包從LifeCycleSavings這個例子:
pop75 dpi ddpi
sr 0.317 0.220 0.305
pop15 -0.908 -0.756 -0.048
我可以繪製一個heatmap像這樣:
library(reshape2)
melted_cors <- melt(cors)
library(ggplot2)
ggplot(melted_cors, aes(Var2, Var1, fill = value)) +
geom_tile(color = "white") +
geom_text(aes(Var2, Var1, label = value), color = "black", size = 4) +
scale_fill_gradient2(low = "blue", mid = "white", high = "red",
midpoint = 0, limit = c(0,1), space = "Lab",
name="Pearson\nCorrelation") +
theme_minimal() +
theme(title = element_blank(), legend.position="none") +
coord_fixed()
有沒有辦法從這個輸出剝去前導零?
你說的前導零的意思究竟是什麼?你想隱藏零相關術語嗎?你是否想將所有相關值乘以10來刪除小數點之前的零點? – Eumenedies
不可重複。什麼是'cors'? – hrbrmstr