【发布时间】:2019-01-06 10:36:30
【问题描述】:
我有以下df:
frequency name sample_type exist
1: 0.0115 sam 1 1
2: 0.3000 sam 2 0
3: 0.0000 sam 3 0
4: 0.0141 bill 1 1
5: 0.0124 bill 3 1
6: 0.0000 bill 2 0
7: 0.0136 mike 3 1
8: 0.0000 mike 1 0
9: 0.0000 mike 2 0
10: 0.0112 leo 1 1
11: 0.0000 leo 2 0
12: 1.0000 leo 3 0
13: 0.0108 brad 3 1
14: 0.0000 brad 2 0
15: 0.9900 brad 1 0
16: 0.0286 randy 3 1
17: 0.0000 randy 2 0
18: 0.7000 randy 1 0
我想创建平铺图/热图,所以我写了脚本:
library(data.table)
ra_df <- fread("G:\\My Drive\\Net2\\test_1.csv",
select=c(1,2,3,4))
library(ggplot2)
ra_figure <- ggplot(ra_df, aes(name, factor(sample_type), fill = frequency)) +
geom_tile(colour="white",size=0.25) +
scale_fill_gradientn(colours = c("white", "lightgreen"), values = c(0,1)) +
theme(axis.text.x = element_text(angle = 90, hjust=1),
legend.position="none", axis.title.x = element_blank(),axis.title.y = element_blank(),
plot.title = element_text(hjust = 0.5,family = "Helvetica", face = "bold.italic", size = (15),
colour="steelblue4"))+
scale_x_discrete(position = "top") +
scale_y_discrete(labels=c("3"="c","2"="b", "1"="a"),expand=c(0,0))+
coord_fixed(ratio = 3)
正如您所见,填充值之间存在很大差异,因此低值看起来是白色的,就像零值一样。较低的值对我来说很重要。
我怎样才能创建这个数字,以便较低的值也可见?
【问题讨论】: