Rで等高線など3軸データのプロット

Rで等高線など3軸データのプロット

##

d<-data.frame(y=tmp2$LIFE_TIME,x1=tmp2$TINRYOU,x2=tmp2$TIKUNENSUU)
d2<-d%>% dplyr::filter(x2<=25 & x1<=10^5) %>% dplyr::group_by(x1=10000*round(x1/10000),x2=2*round(x2/2)) %>% dplyr:: summarise(y=mean(y)) %>% arrange(x2,x1)
p1<-ggplot(d2)
p1<-p1+geom_point(aes(x=x1,y=y,colour=(x2)))
print(p1)


p1<-ggplot(d2)
p1<-p1+geom_point(aes(x=x2,y=y,colour=paste(x1)))
print(p1)


###
d2<-d%>% dplyr::filter(x2<=25 & x1<=10^5) %>% dplyr::group_by(x1=10000*round(x1/10000),x2=2*round(x2/2)) %>% dplyr:: summarise(y=median(y)) %>% arrange(x2,x1)

d3<-d2 %>% tidyr::spread(key=x1,value=y)

image(x=d3[[1]], y=as.numeric(names(d3[-1])),z=as.matrix(d3[,-1]),col=terrain.colors(100))
#contour(x=as.numeric(rownames(d3[,1])),y=as.numeric(colnames(d3[1,])[-1]),as.matrix(d3),nlevel=10,add=T)
contour(x=d3[[1]],y=as.numeric(names(d3[-1])),z=as.matrix(d3[,-1]),nlevel=10,add=T)

abline(v=median(tmp2$TIKUNENSUU),lty=2,col=6,lwd=2)
abline(h=median(tmp2$TINRYOU),lty=2,col=6,lwd=2)