[R] Retrieve Axis coordinates from map
Julien Million
lienju at yahoo.fr
Fri Jul 25 10:30:12 CEST 2014
Thanks you both, very useful!
On 25/07/14 03:20, "David Winsemius" <dwinsemius at comcast.net> wrote:
>
>On Jul 24, 2014, at 2:05 PM, Julien Million wrote:
>
>> Hi,
>>
>> i want to automatise the creation of some maps with R, however, I would
>>need
>> to be able to retrieve the coordinates of the axes that R is
>>automatically
>> generated.
>>
>> When using the package MAPS,
>
>Case matters in R so this is the wrong spelling.
>
>> and creating a map, R will automatically adjust
>> the plot to the region that you are plotting.
>>
>> for example the two command:
>> map(regions="Morocco")
>> or
>> map(regions="France")
>> will generate plots with completely different axis and scale. If I want
>>to
>> automatically generate a map and add a legend to it, I would need to be
>>able
>> to retrieve the coordinates of my axis that were automatically
>>generated in
>> order to give coordinate to place my legend on the map.
>>
>> Basically I would like to automatise the following with a function, and
>>be
>> able to automatically get the coordinates for my legend)
>>
>
>require(maps)
>> map(regions="Morocco")
>> map.axes()
>> legend(-12,34, "blablabla")
>
>Perhaps something like this:
>legend(-12,35.5, paste( paste("Xrange = ", round( par("usr")[1:2],2),
>collapse=" "),
> paste( "Yrange = ", round( par("usr")[3:4],2) ,
>collapse=" "),
> sep="\n") )
>
>?par # since pkg::maps uses base graphics.
>
>>
>> map(regions="France")
>> map.axes()
>> legend(-150,40, "blablabla")
>>
>> mapcountry <- function(country) {
>> map(regions=country)
>> map.axes()
>> legend(xxxx, yyyy, "blablabla")
>> }
>>
>> I want to be able to extract the xxxx and yyyy automatically to be able
>>to
>> generate the legend within the function.
>>
>> Thanks
>>
>> Julien
>>
>>
>>
>> [[alternative HTML version deleted]]
>
>r-help is a plain text mailing list.
>>
>> PLEASE do read the posting guide
>>http://www.R-project.org/posting-guide.html
>
>And thank you for providing working code.
>--
>David Winsemius
>Alameda, CA, USA
>
More information about the R-help
mailing list