[R-sig-Geo] Need help with spatial data plotting

Roman Luštrik roman.lustrik at gmail.com
Thu Feb 14 10:41:16 CET 2013


I suggest you run the code step by step and examine what happens. By
reading help files along the way will bring you closer to
understanding the code than you imagined.

Here are a few hints I hope you may find helpful.

> data(eberg)
This loads a dataset called `eberg`

First, run coordinates(eberg). Error, right?
Error in .checkNumericCoerce2double(obj) :
  cannot retrieve coordinates from non-numeric elements

Now run
> coordinates(eberg) <- ~X+Y
This sets the "default" coordinates of this object. Inspect it with
str(eberg) and you will see you're now dealing with a
SpatialPointsDataFrame (very
important to remember this!). When you imported the data, it was
"only" a data.frame. It is now enhanced with coordinates, among other
things.

> proj4string(eberg) <- CRS("+init=epsg:31467")
This will set the projection of those coordinates in a data.frame to espg:31467.

> eberg <- eberg[runif(nrow(eberg))<.2, ]
First run nrow(eberg). This is the number of rows data.frame eberg
has. Run runif(nrow(eberg)) and you will notice that you get a lot of
values (nrow(eberg)  many, as a matter of fact) between 0 and 1. By
saying <2, you are asking, which values are smaller than 0.2? If a
value is smaller than 0.2, it will be marked as TRUE and FALSE
otherwise. By putting all this inside [..., ], it makes a convenient
way of extracting random rows from a data.frame.  Values before the
comma means rows, after the comma means columns. Try eberg[1:5, 1:5].
See? If there are no commas, R assumes you mean columns.

> bubble(eberg["CLYMHT_A"])
Calls a bubble plot (see ?bubble) and it takes column "CLYMHT_A" as
data to draw bubbles. If this doesn't work for you, try the example
provided in ?bubble:

data(meuse)
coordinates(meuse) <- c("x", "y") # promote to SpatialPointsDataFrame
bubble(meuse, "cadmium", maxsize = 2.5, main = "cadmium concentrations (ppm)",
    key.entries = 2^(-1:4))

> plotKML(eberg["CLYMHT_A"])
Ibidem, except you can now see the data displayed in Google Earth (or
some other viewer).


Cheers,
Roman


On Thu, Feb 14, 2013 at 10:06 AM, EPBaron <ephraim at epbaron.com> wrote:
>
> Thank you Roman.  I had already looked at the plotKML tutorial.  I found the
> examples fascinating, but I'm afraid it made me feel even more illiterate
> than when I started.  In essence, it told me how to build an elegant watch
> when I'm just trying to tell what time it is.  Or, to use the language
> analogy, it introduced me to poetry when all I can understand is simple
> sentences.  The code that seemed most relevant to what I'm trying to do
> baffles me:
> data(eberg)coordinates(eberg) <- ~X+Yproj4string(eberg) <-
> CRS("+init=epsg:31467")eberg <-
> eberg[runif(nrow(eberg))<.2,]bubble(eberg["CLYMHT_A"])plotKML(eberg["CLYMHT_A"])
>
>
>
>
> --
> View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Need-help-with-spatial-data-plotting-tp7582619p7582626.html
> Sent from the R-sig-geo mailing list archive at Nabble.com.
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo




--
In God we trust, all others bring data.



More information about the R-sig-Geo mailing list