程序出现问题,前面没有问题,最后一步说有问题,然后就懵了。。。。问题如下:
> pdf("f:/1 800.pdf",width=5,height=4)
> print(p)
错误: Aesthetics must be either length 1 or the same as the data (1656324): x, y
> dev.off()
null device
1
脚本如下:
rm(list = ls())
library("ggplot2")
traj <- read.csv("f:/1 800.csv")
y1=15; y2=35
x1=105; x2=125
library("sp")
library("maptools")
library("foreign")
asia <- readShapePoly(file.choose())
outline <- sp2tmap(asia)
outline <- data.frame(long=outline[,2],lat=outline[,3],group=outline[,1])
outline$long[(outline$long>x2)] <- x2
outline$long[(outline$long<x1)] <- x1
outline$lat[(outline$lat>y2)] <- y2
outline$lat[(outline$lat<y1)] <- y1
p <- ggplot(traj,aes(x=traj$lon,y=traj$lat))
p <- p + facet_grid(date~night)
p <- p + geom_polygon(data=outline,aes(x=outline$long,y=outline$lat),colour="grey",linetype=1,size=0.2,fill="white")
p <- p + stat_density2d(aes(alpha = ..level..),size = 0.01, bins = 16, geom = 'polygon')
p <- p + scale_x_continuous(limits=c(x1,x2),expand = c(0,0))
p <- p + scale_y_continuous(limits=c(y1,y2),expand = c(0,0))
#p <- p + theme(legend.position='none')
p <- p + theme(text=element_text(color='black', size=10))
p <- p + coord_equal()
pdf("f:/1 800.pdf",width=5,height=4)
print(p)
dev.off()


雷达卡






京公网安备 11010802022788号







