Re: [R] add single points to a level plot
Thanks. Now it can run and generate plots, but there are the two lines on each of the plots. I don't know the problem for this? Error using packet 1 any(sp) is not TRUE On Thu, Mar 8, 2018 at 8:48 AM, Eric Berger wrote: > You need to load the package 'rasterVis' > > > library(rasterVis) > > HTH, > Eric > > > On Thu, Mar 8, 2018 at 5:11 PM, lily li wrote: > >> Hi all, >> >> I ran the code: >> > s <- stack(replicate(2, raster(matrix(runif(100), 10 >> > xy <- data.frame(coordinates(sampleRandom(s, 10, sp=TRUE)), >> + z1=runif(10), z2=runif(10)) >> > levelplot(s, margin=FALSE, at=seq(0, 1, 0.05)) + >> + layer(sp.points(xy, pch=ifelse(pts$z1 < 0.5, 2, 3), cex=2, col=1), >> columns=1) + >> + layer(sp.points(xy, pch=ifelse(pts$z2 < 0.5, 2, 3), cex=2, col=1), >> columns=2) >> >> And got the error: >> Error in UseMethod("levelplot") : >> no applicable method for 'levelplot' applied to an object of class >> "c('RasterStack', 'Raster', 'RasterStackBrick', 'BasicRaster')" >> >> what is the problem? Thanks. >> >> On Thu, Mar 8, 2018 at 12:07 AM, lily li wrote: >> >> > Hi all, >> > >> > I'm trying to add single points with known coordinates to a level plot, >> > but could not find the proper answer. I got to know that layer() >> function >> > is good for this, but I don't know which package is related to this >> > function. The source is here: >> > https://stackoverflow.com/questions/28597149/add-xy-points- >> to-raster-map- >> > generated-by-levelplot >> > >> > but my question is a little different as I know the coordinates of the >> > single point, rather than a range. Thanks for any help you could >> provide. >> > >> >> [[alternative HTML version deleted]] >> >> __ >> R-help@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/posti >> ng-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > [[alternative HTML version deleted]] __ R-help@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.
Re: [R] add single points to a level plot
library(sos) findFn( "layer" ) findFn( "levelplot" ) Also, experts in spatial analysis tend to answer questions on the special mailing list where the Posting Guide says they should. Read it to find out where that is. -- Sent from my phone. Please excuse my brevity. On March 8, 2018 7:11:34 AM PST, lily li wrote: >Hi all, > >I ran the code: >> s <- stack(replicate(2, raster(matrix(runif(100), 10 >> xy <- data.frame(coordinates(sampleRandom(s, 10, sp=TRUE)), >+ z1=runif(10), z2=runif(10)) >> levelplot(s, margin=FALSE, at=seq(0, 1, 0.05)) + >+ layer(sp.points(xy, pch=ifelse(pts$z1 < 0.5, 2, 3), cex=2, col=1), >columns=1) + >+ layer(sp.points(xy, pch=ifelse(pts$z2 < 0.5, 2, 3), cex=2, col=1), >columns=2) > >And got the error: >Error in UseMethod("levelplot") : > no applicable method for 'levelplot' applied to an object of class >"c('RasterStack', 'Raster', 'RasterStackBrick', 'BasicRaster')" > >what is the problem? Thanks. > >On Thu, Mar 8, 2018 at 12:07 AM, lily li wrote: > >> Hi all, >> >> I'm trying to add single points with known coordinates to a level >plot, >> but could not find the proper answer. I got to know that layer() >function >> is good for this, but I don't know which package is related to this >> function. The source is here: >> >https://stackoverflow.com/questions/28597149/add-xy-points-to-raster-map- >> generated-by-levelplot >> >> but my question is a little different as I know the coordinates of >the >> single point, rather than a range. Thanks for any help you could >provide. >> > > [[alternative HTML version deleted]] > >__ >R-help@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. __ R-help@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.
Re: [R] add single points to a level plot
You need to load the package 'rasterVis' > library(rasterVis) HTH, Eric On Thu, Mar 8, 2018 at 5:11 PM, lily li wrote: > Hi all, > > I ran the code: > > s <- stack(replicate(2, raster(matrix(runif(100), 10 > > xy <- data.frame(coordinates(sampleRandom(s, 10, sp=TRUE)), > + z1=runif(10), z2=runif(10)) > > levelplot(s, margin=FALSE, at=seq(0, 1, 0.05)) + > + layer(sp.points(xy, pch=ifelse(pts$z1 < 0.5, 2, 3), cex=2, col=1), > columns=1) + > + layer(sp.points(xy, pch=ifelse(pts$z2 < 0.5, 2, 3), cex=2, col=1), > columns=2) > > And got the error: > Error in UseMethod("levelplot") : > no applicable method for 'levelplot' applied to an object of class > "c('RasterStack', 'Raster', 'RasterStackBrick', 'BasicRaster')" > > what is the problem? Thanks. > > On Thu, Mar 8, 2018 at 12:07 AM, lily li wrote: > > > Hi all, > > > > I'm trying to add single points with known coordinates to a level plot, > > but could not find the proper answer. I got to know that layer() function > > is good for this, but I don't know which package is related to this > > function. The source is here: > > https://stackoverflow.com/questions/28597149/add-xy- > points-to-raster-map- > > generated-by-levelplot > > > > but my question is a little different as I know the coordinates of the > > single point, rather than a range. Thanks for any help you could provide. > > > > [[alternative HTML version deleted]] > > __ > R-help@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. > [[alternative HTML version deleted]] __ R-help@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.
Re: [R] add single points to a level plot
Hi all, I ran the code: > s <- stack(replicate(2, raster(matrix(runif(100), 10 > xy <- data.frame(coordinates(sampleRandom(s, 10, sp=TRUE)), + z1=runif(10), z2=runif(10)) > levelplot(s, margin=FALSE, at=seq(0, 1, 0.05)) + + layer(sp.points(xy, pch=ifelse(pts$z1 < 0.5, 2, 3), cex=2, col=1), columns=1) + + layer(sp.points(xy, pch=ifelse(pts$z2 < 0.5, 2, 3), cex=2, col=1), columns=2) And got the error: Error in UseMethod("levelplot") : no applicable method for 'levelplot' applied to an object of class "c('RasterStack', 'Raster', 'RasterStackBrick', 'BasicRaster')" what is the problem? Thanks. On Thu, Mar 8, 2018 at 12:07 AM, lily li wrote: > Hi all, > > I'm trying to add single points with known coordinates to a level plot, > but could not find the proper answer. I got to know that layer() function > is good for this, but I don't know which package is related to this > function. The source is here: > https://stackoverflow.com/questions/28597149/add-xy-points-to-raster-map- > generated-by-levelplot > > but my question is a little different as I know the coordinates of the > single point, rather than a range. Thanks for any help you could provide. > [[alternative HTML version deleted]] __ R-help@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.
Re: [R] Names of variables needed in newdata for predict.glm
Hi Bendix, If the 'model' argument to glm() is TRUE (the default), you can get the structure of the model frame that was used to fit the model, by using: > str(mx$data) 'data.frame': 200 obs. of 4 variables: $ D: int 0 1 0 1 1 0 1 1 1 1 ... $ x: num 0.705 2.15 0.572 1.249 0.807 ... $ f: Factor w/ 4 levels "a","b","c","d": 1 4 1 4 4 1 4 2 4 4 ... $ Y: num 0.787 8.267 3.085 5.738 9.593 ... > str(mi$data) 'data.frame': 200 obs. of 4 variables: $ D: int 0 1 0 1 1 0 1 1 1 1 ... $ x: num 0.705 2.15 0.572 1.249 0.807 ... $ f: Factor w/ 4 levels "a","b","c","d": 1 4 1 4 4 1 4 2 4 4 ... $ Y: num 0.787 8.267 3.085 5.738 9.593 ... The first column in the data frame will be the response variable. In both cases, the offset variable 'Y' is included, whether the offset was part of the formula or specified as a separate argument. You can then process the results as you need from there, such as: > sapply(mx$data, class) D x f Y "integer" "numeric" "factor" "numeric" Regards, Marc Schwartz > On Mar 8, 2018, at 12:26 AM, Marc Girondot via R-help > wrote: > > Hi, > > Some try: > > names(mi$xlevels) > [1] "f" > > all.vars(mi$formula) > [1] "D" "x" "f" "Y" > > names(mx$xlevels) > [1] "f" > > all.vars(mx$formula) > [1] "D" "x" "f" > > When offset is indicated out of the formula, it does not work... > > Marc > > Le 07/03/2018 à 06:20, Bendix Carstensen a écrit : >> I would like to extract the names, modes [numeric/factor] and levels >> of variables needed in a data frame supplied as newdata= argument to >> predict.glm() >> >> Here is a small example illustrating my troubles; what I want from >> (both of) the glm objects is the vector c("x","f","Y") and an >> indication that f is a factor: >> >> library( splines ) >> dd <- data.frame( D = sample(0:1,200,rep=T), >> x = abs(rnorm(200)), >> f = factor(sample(letters[1:4],200,rep=T)), >> Y = runif(200,0.5,10) ) >> mx <- glm( D ~ ns(x,knots=1:2,Bo=c(0,5)) + f:I(x^2) , offset=log(Y) , >> family=poisson, data=dd) >> mi <- glm( D ~ ns(x,knots=1:2,Bo=c(0,5)) + f:I(x^2) + offset(log(Y)), >> family=poisson, data=dd) >> >> attr(mx$terms,"dataClasses") >> attr(mi$terms,"dataClasses") >> mi$xlevels >> mx$xlevels >> >> ...so far not quite there. >> >> Regards, >> >> Bendix Carstensen >> >> Senior Statistician >> Steno Diabetes Center >> Clinical Epidemiology >> Niels Steensens Vej 2-4 >> DK-2820 Gentofte, Denmark >> b...@bxc.dk >> bendix.carsten...@regionh.dk >> http://BendixCarstensen.com [[alternative HTML version deleted]] __ R-help@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.