다각형이있는 stat_contour
을 사용하면 데이터가 없기 때문에 일부 영역을 채우지 않아야합니다. 누구든지 그것을 피하는 방법을 알고 있습니까? 또한, 축과 플롯 영역 사이에 공간이 있습니다. 어떻게 제거할까요?! 여기 r stat_contour 다각형으로 채우기가 올바르지 않음
plot_contour <- function (da, native) {
h2d<-hist2d(da$germ_div,da[[native]],nbins=40,show=F)
h2d$counts<-h2d$counts+1
counts<-log(h2d$counts, base=10)
rownames(counts)<-h2d$x
colnames(counts)<-h2d$y
counts<-melt(counts)
names(counts)<-c('x','y','z')
ggplot(counts,aes(x,y))+
stat_contour(expand=c(0,0),aes(z=z,fill=..level..),geom='polygon')+
stat_contour(data=counts[counts$x<=75,],aes(z=z,fill=..level..),bins=50,geom='polygon')+
scale_fill_gradientn(expand=c(0,0),colours=rainbow(1000),
limits=c(log(2,base=10),4),na.value='white',guide=F)+
geom_contour(aes(z=z,colour=..level..),size=1.5)+
scale_color_gradientn(colours=rainbow(30),limits=c(log(2,base=10),4),na.value='white',
guide=F) + theme_bw()+
scale_x_continuous(expand=c(0,0),limits=c(0,50))+
scale_y_continuous(expand=c(0,0),limits=c(40,100))+
labs(x=NULL, y=NULL, title=NULL)+
theme(axis.text.x = element_text(family='Times', colour="black", size=20, angle=NULL,
hjust=NULL,vjust=NULL,face="plain"),
axis.text.y = element_text(family='Times', colour="black", size=20,angle=NULL,
hjust=NULL,vjust=NULL,face="plain")
)
}
da<-read.table('test.txt',header=T)
i<-'test'
plot_contour(da,i)