나는 ggplot2
의 geom_raster()
을 사용해야한다고 생각합니다. 다음은 합성 된 데이터를 사용하는 예입니다. 먼저 30x30 격자를 작성한 다음이를 모든 x/y 집계로 잘라내는 방법을 보여줍니다.
require(ggplot2)
require(plyr)
## CREATE REASONABLE SIZE GRID 30x30
dfe<-expand.grid(ENT_LATITU=seq(415000,418000,100),
ENT_LONGIT=seq(630000,633000,100),
CSK=0)
## FILL WITH RANDOM DATA
dfe$CSK=round(rnorm(nrow(dfe),200,50),0)
#######################################################
##### VALUES TO CHANGE IN THIS BLOCK #####
#######################################################
## TRIM ORIGINAL DATASET
lat.max<-Inf # change items to trim data
lat.min<-0
long.max<-Inf
long.min<-631000
dfe.trim<-dfe[findInterval(dfe$ENT_LATITU,c(lat.min,lat.max))*findInterval(dfe$ENT_LONGIT,c(long.min,long.max))==1,]
## SUMMARIZE TO NEW X/Y GRID
xblocks<-6
yblocks<-8
## GRAPH COLOR AND TEXT CONTROLS
showText<-TRUE
txtSize<-3
heatmap.low<-"lightgreen"
heatmap.high<-"orangered"
#######################################################
##### #####
#######################################################
## BASIC PLOT (ALL DATA POINTS)
ggplot(dfe) +
geom_raster(aes(ENT_LATITU,ENT_LONGIT,fill=CSK)) + theme_bw() +
scale_fill_gradient(low=heatmap.low, high=heatmap.high) +
geom_text(aes(ENT_LATITU,ENT_LONGIT,label=CSK,fontface="bold"),
color="black",
size=2.5)
기본 줄거리 : 다음
![enter image description here](https://i.stack.imgur.com/I7Xpc.png)
집계 줄거리 : 당신이 shp-에 대한 객체를 생성 된 코드를 제공하는 경우
## CALL ddply to roll-up the data and calculate summary means, SDs,ec
dfe.plot<-ddply(dfe.trim,
.(lat=cut(dfe.trim$ENT_LATITU,xblocks),
long=cut(dfe.trim$ENT_LONGIT,yblocks)),
summarize,
mean=mean(CSK),
sd=sd(CSK),
sum=sum(CSK),
range=paste(min(CSK),max(CSK),sep="-"))
## BUILD THE SUMMARY CHART
g<-ggplot(dfe.plot) +
geom_raster(aes(lat,long,fill=sum),alpha=0.75) +
scale_fill_gradient(low=heatmap.low, high=heatmap.high) +
theme_bw() + theme(axis.text.x=element_text(angle=-90)) +
ggtitle(paste(xblocks,
" X ",
yblocks,
" grid of Catch Data\nbetween (",
min(dfe.trim$ENT_LATITU),
" : ",
min(dfe.trim$ENT_LONGIT),
") and (",
max(dfe.trim$ENT_LATITU),
" : ",
max(dfe.trim$ENT_LONGIT),
")\n\n",
sep=""))
## ADD THE LABELS IF NEEDED
if(showText)g<-g+geom_text(aes(lat,long,label=paste("SUM=",round(sum,0),
"\nMEAN=",round(mean,1),
"\nSD=",round(sd,1),
"\nRNG=",range,sep=""),
fontface=c("italic")),
color="black",size=txtSize)
## FUDGE THE LABELS TO MAKE MORE READABLE
## REPLACE "," with newline and "]" with ")"
g$data[,1:2]<-gsub("[,]",replacement=" to\n",x=as.matrix(g$data[,1:2]))
g$data[,1:2]<-gsub("]",replacement=")",x=as.matrix(g$data[,1:2]))
## PLOT THE CHART
g + labs(x="\nLatitude", y="Longitude\n", fill="Sum\nBlock\n")
## SHOW HEADER OF data.plot
head(dfe.plot)
![enter image description here](https://i.stack.imgur.com/tPOMs.png)
그것은 더 나은 것 객체와 그와 유사한 범위 스펙 당신이 작업 할 객체들. –