[R-sig-Geo] readShapePoly function and putting text on map

Roger Bivand Roger.Bivand at nhh.no
Thu Dec 16 11:20:39 CET 2010


On Thu, 16 Dec 2010, Wang, Kevin (SYD) wrote:

> Hi all,
>
> I've managed to draw a map using the following code:
> 	lga1 <- readShapePoly("D:/Documents and Settings/kevinwang/My
> Documents/SMS/ASGC/LGA10aAust", IDvar = "LGA_CODE10")
> 	plot(lga1[lga1$STATE_CODE == 7,], border="blue")
> 	title(main = "NT LGA Division")
> 	text(coordinates(lga1[lga1$STATE_CODE == 7,]), labels =
> sapply(slot(lga1[lga1$STATE_CODE == 7,], "polygons"),
>
> function(i) slot(i, "ID")), cex=0.6)
>
> This gives me a map of Northern Territory (Australia), with local
> government division LGA and the code for the LGAs in each LGA.
>
> However, instead of the LGA code, I'm trying to use LGA names (which is
> in a variable called LGA_NAME10) instead.  But when I tried to change
> the IDvar I got:
> 	> lga1 <- readShapePoly("D:/Documents and Settings/kevinwang/My
> Documents/SMS/ASGC/LGA10aAust", IDvar = "LGA_NAME10")
> 	Error in `row.names<-.data.frame`(`*tmp*`, value = c("Albury
> (C)", "Armidale Dumaresq (A)",  :
> 	  duplicate 'row.names' are not allowed
> 	In addition: Warning message:
> 	non-unique value when setting 'row.names': 'Campbelltown (C)'
>
> My guess is that there are duplicated names in LGA_NAME10 variable.  So
> I'm wondering if it's possible to specify "LGA_NAME10" in the text()
> function instead?

Maybe:
         lga1_7 <- lga1[lga1$STATE_CODE == 7,]
         plot(lga1_7, border="blue")
         title(main = "NT LGA Division")
         text(coordinates(lga1_7),
             labels = as.character(lga1_7$LGA_NAME10), cex=0.6)

(above you could have said labels=rownames(lga1)[lga1$STATE_CODE == 7], 
the example on the help hasn't been updated, but will be now - thanks 
for reminding me).

Roger

>
> Thanks in advance for the help!
>
> Cheers
> Kevin
>
>
>
> Kevin Wang
> Senior Adviser, Government Advisory Services
> Advisory
>
> KPMG
> 10 Shelley Street
> Sydney  NSW  2000  Australia
>
> Tel 	+61 2 9335 8282
> Fax	+61 2 9335 7001
> Mob	0404 518 301
> kevinwang at kpmg.com.au <mailto:kevinwang at kpmg.com.au >
>
> kpmg.com.au <http://kpmg.com.au/>
>
> Best Accounting Firm - BRW Client Choice Awards 2010
>
> Protect the environment: please think before you print
>
>
>
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no



More information about the R-sig-Geo mailing list