[R] Trouble with Spatial Data Example Script

David L Carlson dcarlson at tamu.edu
Sat Aug 11 21:11:12 CEST 2012


That is it. If you are going to use source() change

spplot(gadm, "language", col.regions=col, main="Swiss Language
  Regions")

To

print(spplot(gadm, "language", col.regions=col, main="Swiss Language
  Regions"))

-------
David


> -----Original Message-----
> From: R. Michael Weylandt [mailto:michael.weylandt at gmail.com]
> Sent: Saturday, August 11, 2012 12:27 PM
> To: Lorenzo Isella
> Cc: dcarlson at tamu.edu; John Kane; r-help at stat.math.ethz.ch
> Subject: Re: [R] Trouble with Spatial Data Example Script
> 
> I have no experience with spplot() or maps in general, but might this
> be more or less tied to R FAQ 7.22?
> 
> Michael
> 
> On Sat, Aug 11, 2012 at 12:00 PM, Lorenzo Isella
> <lorenzo.isella at gmail.com> wrote:
> > Hello,
> > The situation is a bit odd.
> > If I open an R session and I paste there the script, then it does
> work.
> > However, if I save it as a text file and then I run it with the
> > source("myfile.R") command, then I fall back to the case that started
> this
> > thread i.e. I see nothing.
> > Does anybody have a clue at what is going on?
> > I paste below the output of sessionInfo(), which is the same no
> matter
> > whether I paste the commands in a shell or use a .R file.
> >
> >
> > sessionInfo()
> > R version 2.15.1 (2012-06-22)
> > Platform: x86_64-pc-linux-gnu (64-bit)
> >
> > locale:
> >  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
> >  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
> >  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
> >  [7] LC_PAPER=C                 LC_NAME=C
> >  [9] LC_ADDRESS=C               LC_TELEPHONE=C
> > [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
> >
> > attached base packages:
> > [1] stats     graphics  grDevices utils     datasets  methods   base
> >
> > other attached packages:
> > [1] sp_0.9-99
> >
> > loaded via a namespace (and not attached):
> > [1] grid_2.15.1    lattice_0.20-6
> >
> >
> > Many thanks
> >
> > Lorenzo
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > On Sat, 11 Aug 2012 17:18:43 +0200, David L Carlson
> <dcarlson at tamu.edu>
> > wrote:
> >
> >> Can you get other plotting commands to work? E.g.
> >>
> >> plot(1:5, 1:5)
> >>
> >>> -----Original Message-----
> >>> From: Lorenzo Isella [mailto:lorenzo.isella at gmail.com]
> >>> Sent: Saturday, August 11, 2012 3:20 AM
> >>> To: dcarlson at tamu.edu
> >>> Subject: Re: [R] Trouble with Spatial Data Example Script
> >>>
> >>> Thanks for your reply.
> >>> I am running R 2.15.1 on debian testing, amd64 architecture.
> >>>
> >>>
> >>>
> >>>
> >>> ~$ R
> >>>
> >>> R version 2.15.1 (2012-06-22) -- "Roasted Marshmallows"
> >>> Copyright (C) 2012 The R Foundation for Statistical Computing
> >>> ISBN 3-900051-07-0
> >>> Platform: x86_64-pc-linux-gnu (64-bit)
> >>>
> >>>
> >>> and when I run the script, this is what I see
> >>>
> >>>
> >>>
> >>> source('map-switzerland.R')
> >>> [1] "gadm"
> >>>
> >>> gadm contains the data, but I do not see any map.
> >>> Any hint about what is going on?
> >>> Cheers
> >>>
> >>> Lorenzo
> >>>
> >>>
> >>>
> >>>
> >>>
> >>> On Fri, 10 Aug 2012 23:43:34 +0200, David L Carlson
> <dcarlson at tamu.edu>
> >>> wrote:
> >>>
> >>> > The script is working for me. Did you get any error or warning
> >>> messages?
> >>> > What version of R are you using? What operating system does your
> >>> > computer use? When the command, print(load(con)), runs, what
> message
> >>> do
> >>> > you see?
> >>> >
> >>> > ----------------------------------------------
> >>> > David L Carlson
> >>> > Associate Professor of Anthropology
> >>> > Texas A&M University
> >>> > College Station, TX 77843-4352
> >>> >
> >>> >
> >>> >> -----Original Message-----
> >>> >> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> >>> >> project.org] On Behalf Of Lorenzo Isella
> >>> >> Sent: Friday, August 10, 2012 3:21 PM
> >>> >> To: r-help at stat.math.ethz.ch
> >>> >> Subject: [R] Trouble with Spatial Data Example Script
> >>> >>
> >>> >> Dear All,
> >>> >> I need to do something relatively simple: generate a map of
> Europe
> >>> and
> >>> >> paint the various states with different colors (only 3-4 are
> needed)
> >>> >> according to a rule.
> >>> >> I would like to keep it as simple as possible and the script
> >>> resorting
> >>> >> to
> >>> >> the sp package that I found at
> >>> >>
> >>> >> http://bit.ly/Oc71ub
> >>> >>
> >>> >> is exactly what I am looking for (I need to repeat the exercise
> with
> >>> >> Europe instead of Switzerland and to have a legend).
> >>> >> However, when I try to run the script (which I also paste at the
> end
> >>> of
> >>> >> the email), well, nothing happens and I certainly do not see a
> map
> >>> of
> >>> >> Switzerland.
> >>> >> I am not familiar with the sp package, but am I missing the
> obvious?
> >>> >> Any help is appreciated.
> >>> >> Best Regards
> >>> >>
> >>> >> Lorenzo
> >>> >>
> >>> >> ########################################à
> >>> >>
> >>> >> library(sp)
> >>> >> con <- url("http://gadm.org/data/rda/CHE_adm1.RData")
> >>> >> print(load(con))
> >>> >> close(con)
> >>> >>
> >>> >>
> >>> >>
> >>> >> language <- c("german", "german", "german","german",
> >>> >>   "german","german","french", "french",
> >>> >>   "german","german","french", "french",
> >>> >>   "german", "french","german","german",
> >>> >>   "german","german","german", "german",
> >>> >>   "german","italian","german","french",
> >>> >>   "french","german","german")
> >>> >> gadm$language <- as.factor(language)
> >>> >> col = rainbow(length(levels(gadm$language)))
> >>> >> spplot(gadm, "language", col.regions=col, main="Swiss Language
> >>> >> Regions")
> >>> >>
> >>> >> ###########################################
> >>> >>
> >>> >> ______________________________________________
> >>> >> R-help at r-project.org mailing list
> >>> >> 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.
> >
> > ______________________________________________
> > R-help at r-project.org mailing list
> > 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