[R] labelCoubtries() doesn't work. Where is my mistake?

paladini at trustindata.de paladini at trustindata.de
Mon Jan 19 15:32:15 CET 2015


Hi Jim,
that is exactly what I was looking for. Thanks a lot! I can even  
choose how to label the countries e.g. Italy or just IT.

Have a nice day and thank you for helping me again

Claudia


Zitat von Jim Lemon <drjimlemon at gmail.com>:

> Hi Claudia,
> You're right, when the map is maximized the coordinates of the objects
> aren't maintained. I wrote a simple example using boxed.labels instead
> of identifyCountries:
>
> mapCountryData(mapRegion="europe", oceanCol="slateblue1",
> missingCountryCol="darkgrey", colourPalette=c("palegreen","darkgreen"),
> mapTitle="European Participation Index")
> require(plotrix)
> loc_box_lab<-function(x,...) {
>  for(boxlab in x) {
>   cat("Click in",boxlab,"\n")
>   boxed.labels(x=locator(1),labels=boxlab,...)
>  }
> }
> country_labels=c("UK","France","Spain","Germany","Italy","Holland",
>  "Denmark","Norway","Sweden","Greece")
> loc_box_lab(country_labels)
>
> and when the labels were initially placed, they looked fine. Upon
> maximizing the graphics window, not only were the labels displaced,
> but the color legend at the bottom was as well. It appears to be
> connected with the aspect ratio of the image. However, if I draw the
> initial map using:
>
> require(maps)
> map(xlim=c(-10,50),ylim=c(35,70))
>
> and then add the labels in the same way, the spatial relationship of
> labels and map stays the same when maximized .
>
> Jim
>
>
> On Mon, Jan 19, 2015 at 2:24 AM,  <paladini at trustindata.de> wrote:
>> Hi Jim,
>> thanks again for your help! Yes I am using the "rworldmap" package.
>> identifyCountries() works.
>> But I am not entirley happy with this solution. You have to click on all 27
>> countries and when your position is not perfect you get e.g. "Vatican" or
>> "Monaco" instead of "Italy" and you have to start all over again. Moreover
>> when I maximize the picture all country-labels vanish or shift to the wrong
>> place.
>> There ought to be a way to do it somehow more comfortable.
>>
>> Have a nice sunda and best regards!
>>
>> Claudia
>>
>>
>> .
>> Zitat von Jim Lemon <drjimlemon at gmail.com>:
>>
>>
>>> Hi Claudia,
>>> It seems that you are using the "rworldmap" package. The simplest
>>> solution to your problem seems to be the "identifyCountries" function.
>>> Just call:
>>>
>>> identifyCountries()
>>>
>>> instead of "labelCountries" and left click on the countries you want
>>> labeled.
>>>
>>> Jim
>>>
>>>
>>> On Sat, Jan 17, 2015 at 3:33 AM,  <paladini at trustindata.de> wrote:
>>>>
>>>> Hello,
>>>> I have problems to label countries in my map.
>>>>
>>>> I use the following code to draw the map:
>>>>
>>>>
>>>>
>>>> epimap=joinCountryData2Map(epidata,joinCode="NAME",nameCountryColumn="Country",nameJoinColumn="Country")
>>>> mapCountryData(epimap, nameColumnToPlot="EPI.2.0" ,mapRegion="europe",
>>>> oceanCol="slateblue1",
>>>> missingCountryCol="darkgrey", colourPalette=c("palegreen","darkgreen"),
>>>> mapTitle="European Participation Index")
>>>>
>>>> That works without any problems.
>>>>
>>>>  When I use labelCountries() afterwards all countries are named,
>>>> including
>>>> Isle of Man, San Marino etc.
>>>>  and the map becomes quite confusing.
>>>>
>>>> Therefore I want to label only the 27 countries contained in my data.
>>>>
>>>> In order to get their coordinates I use the following routine:
>>>>
>>>> country_index= c()
>>>> j=1
>>>> for (i in 1:244){
>>>>         if  (!is.na(epimap[["Country"]][i])){
>>>>                 country_index[j]=i
>>>>                 j=j+1
>>>>         }
>>>>
>>>>
>>>>
>>>> }
>>>>
>>>> LON=epimap[['LON']][namei]
>>>> LAT=epimap[['LAT']][namei]
>>>>
>>>> epidata_spat=cbind(epidata, LON,LAT)
>>>>
>>>> It is a bit pedestrian but I dont't know how to do it more elegantly.
>>>> Nevertheless it works.
>>>>
>>>> Now I use
>>>>
>>>>
>>>> labelCountries(dF="epidata_spat",nameCountryColumn ="Country",
>>>> nameX="LON",
>>>> nameY="LAT")
>>>>
>>>>
>>>> But nothing happens. There is neither an error message nor
>>>> country-labels.
>>>>
>>>> I haven't the faintest idea why it doesn't work or how to do it properly.
>>>> It would be really nice if somebody could help me.
>>>>
>>>>
>>>>
>>>> Best regards and thanking you in anticipation!
>>>>
>>>> Claudia
>>>>
>>>> ______________________________________________
>>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>>> PLEASE do read the posting guide
>>>> http://www.R-project.org/posting-guide.html
>>>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>>



More information about the R-help mailing list