[R-sig-Geo] stplot - legend/classes of categorical vairable
Edzer Pebesma
edzer.pebesma at uni-muenster.de
Wed Mar 4 19:12:37 CET 2015
Hi Richard, stplot as it is on CRAN does not support factor variables. I
added this support to the dev version on github, e.g. try this
(reproducible!) example:
# install spacetime from github:
devtools::install_github("edzer/spacetime")
library(spacetime)
example(STFDF)
set.seed(42)
gridded(stfdf at sp) = TRUE
stfdf$f = factor(sample(c("a", "b", "c"), 12, replace = TRUE))
library(RColorBrewer)
stplot(stfdf[,,"f"], col.regions = brewer.pal(3, "Accent"))
Make sure that your variable IS a factor, e.g. by
fdf at crop_id = as.factor(fdf at crop_id)
Your data contains many points. If they are laid out on a grid, the plot
improves if you do
gridded(fdf at sp) = TRUE
so that stplot knows, too.
On 03/04/2015 11:45 AM, richard.redweik at posteo.de wrote:
> Hello,
>
> I have an object of class STFDF named 'fdf'. I want to create a stplot
> in which the categorical variable crop_id resp. crop_short is visualized
> per year.
>
> Currently I am only able to assign a color/legend entry to a range of
> crop_ids, e.g. green --> [1, 2], yellow --> (2, 3]:
>
>> col <- brewer.pal(8, "Accent")
>> color <- colorRampPalette(col)(18)
>> stplot(fdf[,, "crop_id"], col.regions=color, cuts=18)
>
> However, this does mean, that the crop_ids 1 and 2 are assigned to green.
> When changing the cuts parameter to cuts=19, I get an unambigious but
> not very readable assignment, e.g. green --> [1, 1.947], yellow -->
> (1.947, 2.895].
>
> Now I am wondering, what is the best way to get one class resp. legend
> entry per crop_id, e.g. green --> 1, yellow --> 2 etc.
>
> Does someone know how to do this?
>
> Thanks in advance,
> Richard
>
> PS:
> Summary of my fdf object:
>
>> summary(fdf)
> Object of class STFDF
> with Dimensions (s, t, attr): (17511, 11, 6)
> [[Spatial:]]
> Object of class SpatialPoints
> Coordinates:
> min max
> x 3464500 3654500
> y 2828500 3026500
> Is projected: NA
> proj4string : [NA]
> Number of points: 17511
> [[Temporal:]]
> Index timeIndex
> Min. :1995-01-01 00:00:00 Min. : 1.0
> 1st Qu.:1997-07-02 12:00:00 1st Qu.: 3.5
> Median :2000-01-01 00:00:00 Median : 6.0
> Mean :2000-01-01 08:43:38 Mean : 6.0
> 3rd Qu.:2002-07-02 12:00:00 3rd Qu.: 8.5
> Max. :2005-01-01 00:00:00 Max. :11.0
> [[Data attributes:]]
> objectid crop_id crop_short year prob
> Min. :3222754 Min. : 1.00 WSWH :79136 Min. :1995 Min. :1
> 1st Qu.:3255362 1st Qu.: 3.00 MAIF :62594 1st Qu.:1997 1st Qu.:1
> Median :3287732 Median :10.00 RAPE :13881 Median :2000 Median :1
> Mean :3289614 Mean :11.56 PULS :10785 Mean :2000 Mean :1
> 3rd Qu.:3322247 3rd Qu.:19.00 WBAR :10095 3rd Qu.:2003 3rd Qu.:1
> Max. :3367519 Max. :19.00 MAIZ : 5069 Max. :2005 Max. :1
> (Other):11061
> nuts_code
> FR25:192621
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
--
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster,
Heisenbergstraße 2, 48149 Münster, Germany; +49 251 83 33081
Journal of Statistical Software: http://www.jstatsoft.org/
Computers & Geosciences: http://elsevier.com/locate/cageo/
Spatial Statistics Society http://www.spatialstatistics.info
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: OpenPGP digital signature
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20150304/41222c5d/attachment.bin>
More information about the R-sig-Geo
mailing list