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

Wang, Kevin (SYD) kevinwang at kpmg.com.au
Thu Dec 16 11:31:11 CET 2010


Thanks, Roger,

Got it to work. 

Got another question, is it possible to "enlarge" the map either using the plot function, or another function?

Cheers

Kevin 

sent from my hTC Desire handset



----- Reply message -----
From: "Roger Bivand" <Roger.Bivand at nhh.no>
Date: Thu, Dec 16, 2010 9:22 pm
Subject: [R-sig-Geo] readShapePoly function and putting text on map
To: "Wang, Kevin (SYD)" <kevinwang at kpmg.com.au>
Cc: "r-sig-geo at r-project.org" <r-sig-geo at r-project.org>, "Kevin Wang" <wang.kevin at gmail.com>

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

******************************************************************

The information in this e-mail is confidential and may be legally
privileged. It is intended solely for the addressee. Access to this
e-mail by anyone else is unauthorised. If you have received this
communication in error, please notify us immediately by return
e-mail with the subject heading "Received in error" or telephone
+61 2 93357000, then delete the email and destroy any copies of it.
If you are not the intended recipient, any disclosure, copying,
distribution or any action taken or omitted to be taken in reliance
on it, is prohibited and may be unlawful. Any opinions or advice
contained in this e-mail are subject to the terms and conditions
expressed in the governing KPMG client engagement letter. Opinions,
conclusions and other information in this e-mail and any
attachments that do not relate to the official business of the firm
are neither given nor endorsed by it. 

KPMG cannot guarantee that e-mail communications are secure or
error-free, as information could be intercepted, corrupted,
amended, lost, destroyed, arrive late or incomplete, or contain
viruses. 

KPMG, an Australian partnership and a member firm of the KPMG
network of independent member firms affiliated with KPMG
International Cooperative (“KPMG International”), a Swiss entity. 
KPMG International provides no services to clients.  

Liability limited by a scheme approved under Professional Standards
Legislation. 

*******************************


More information about the R-sig-Geo mailing list