全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
2273 2
2016-11-29
library(maps)
library(ggplot2)
library(maptools)
library(directlabels)
library(mapproj)
library(plyr)
library(reshape2)

setwd("E://Ryuyan")
mymap <-readShapePoly("bou2_4p.shp")#读取地图
mymapd <- fortify(mymap)#打散地图为数据框,方便ggplot读取
## Regions defined for each Polygons
temp<-mymap@data#提取地图省份
x<-mymap@data
xs<-data.frame(x,id=seq(0:924)-1)#给省份编写id
china_mapdata<-join(mymapd, xs, type = "full") #将打散的数据以省份分组

geshengdata <- read.csv("gesheng.csv", header = T,
                       sep = ",", stringsAsFactors = F)
NAME <- geshengdata[,1]
fre <- geshengdata[,2]
mydata1<-data.frame(NAME,fre)
mydata1<-join(mydata1,xs,type="full")
fre<-data.frame(NAME,fre)
china_fre<-join(mydata1, fre, type = "full")
id <- mydata1idmyepidat<−data.frame(id=unique(sort(mymapdid)))
shengdata<-read.csv("jw.csv",header = T,
                       sep = ",", stringsAsFactors = F)

temp <- data.frame(NAME =NAME,lat=shengdatajd,long=shengdatawd)#给各地名称一个经纬度


ggplot(myepidat) + geom_map(aes(map_id = id, fill = fre), color = "white", map = mymapd) +
  geom_point(data = temp,aes(x = long, y = lat,fill = NULL),
             color = rgb(red = 165, green = 165, blue = 165, max = 255)) +
  geom_dl(data = temp,aes(x = long, y = lat,label = NAME),
          list('last.points',cex = 0.7, hjust = 1))+#设置省会标签,让省会标签随机移动一点距离以免过分重叠
  scale_fill_gradient(name="",
                      high = rgb(red = 254, green = 67, blue = 101, max = 255),
                      low = rgb(red = 162, green = 162, blue = 145, max = 255),
                      breaks = c(0, 103, 153, 153, 202, 317, 581)) +
coord_map()+
  theme(legend.text=element_text(size=10))

一直出错显示Error in ggplot2::layer(data = data, mapping = mapping, geom = GeomDl,  :
  must specify method= argument。
以前运行同样的程序是没有问题的,求大神解答是什么原因?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2018-7-15 19:16:48
geom_dl(mapping = NULL, data = NULL, ..., method = stop("must specify method= argument"),
    debug = FALSE, na.rm = TRUE, parse = FALSE, stat = "identity",
    position = "identity", inherit.aes = TRUE)
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2018-7-17 09:20:41
经高人指点,这个问题这样解决:
geom_dl(data = temp,aes(x = long, y = lat,label = NAME),
        method = list('last.points',cex = 0.7, hjust = 1))+#设置省会标签,让省会标签随机移动一点距离以免过分重叠,注意加上method = !!!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群