[R-sig-Geo] editing a correlogram

Roger Bivand Roger@B|v@nd @end|ng |rom nhh@no
Mon Mar 18 09:35:53 CET 2019


On Sun, 17 Mar 2019, Leonardo Matheus Servino wrote:

> My script:

No, not your script, a *reproducible* example, using a built-in data set. 
Nobody can run your code without your data, and we don't need your data. 
Did you read my reply? Why have you quoted the numerical arguments - a 
clear error?

For me:

> par(adj=0.5, family="serif", cex.axis=1.5, xaxs="r", cex.axis=2.5,
+  cex.lab=2.5, las=1, tcl=-0.25, lwd=1.8, ps=5, mex=0.7, lty="blank")
> plot(Ispc)

does do something, but whether this is what you consider prettier isn't my 
problem. If you prefer, take the output of the print method and use any 
plotting functionality you chose.

Roger

>
> library(spdep)
> setwd('C:/Dados')
> dados_I_langsdorffii<-read.csv('I_langsdorffii.csv', sep=';')
> coords<-cbind(dados_I_langsdorffii$LONG, dados_I_langsdorffii$LAT)
> coords1<-as.matrix(coords)
> source("plot.links.r")
> plot.links(coords, thresh = 0.5, text = F)
> vizinho<-dnearneigh(as.matrix(coords1), 0, 0.5)
> summary(vizinho)
> corre.sp <- sp.correlogram(vizinho, dados_I_langsdorffii$MEDIANA_CRC, order
> =5, method = "I",zero.policy = TRUE)
> print(corre.sp, p.adj.method = "holm")
> par(adj="0.5",family="serif",cex.axis="1.5",xaxs="r",cex.axis="2.5",cex.lab="2.5",las="1",tcl="-0.25",lwd="1.8",
> ps="5", mex="0.7", lty="blank")
> plot(corre.sp, p.adj.method = "holm", main="",ylim=c(-1,1))
>
> Em sáb, 16 de mar de 2019 às 19:04, Roger Bivand <Roger.Bivand using nhh.no>
> escreveu:
>
>> On Sat, 16 Mar 2019, Ben Tupper wrote:
>>
>>> Hi,
>>>
>>> In this case the spdep::plot.spcor() function, which I think you are
>>> using, doesn't provide the mechanism for the caller to override the
>>> default pch value.  You can see this by looking at the pl.spcor function
>>> (as shown way below.)  I think it may be easiest for you to simply
>>> rewrite the function with the plotting parameters assigned as arguments.
>>
>> Thanks, indeed the ... should be passed through to plotting functions,
>> and I'll look at doing this. My preference would be to extract the
>> components of the returned object needed for customised plotting, not
>> trying to finesse the plot method, which was always meant for guidance,
>> like other diagnostic plots.
>>
>> As Rolf said, an example of the code you are using (on a built-in data
>> set) to show what you want would make things easier, say based on the help
>> page example. Note that print method returns its calculations invisibly
>> too.
>>
>> nc.sids <- st_read(system.file("shapes/sids.shp", package="spData")[1],
>> quiet=TRUE)
>> rn <- as.character(nc.sids$FIPS)
>> ncCC89_nb <- read.gal(system.file("weights/ncCC89.gal",
>> package="spData")[1],
>>   region.id=rn)
>> ft.SID74 <- sqrt(1000)*(sqrt(nc.sids$SID74/nc.sids$BIR74) +
>>    sqrt((nc.sids$SID74+1)/nc.sids$BIR74))
>> tr.SIDS74 <- ft.SID74*sqrt(nc.sids$BIR74)
>> Ispc <- sp.correlogram(ncCC89_nb, tr.SIDS74, order=8, method="I",
>>   zero.policy=TRUE)
>> str(Ispc)
>> str(print(Ispc, "bonferroni"))
>> Ispc_b <- as.data.frame(print(Ispc, "bonferroni"))
>> Ispc_b$lag <- 1:8
>> library(ggplot2)
>> ggplot(Ispc_b) + geom_point(aes(x=lag, y=estimate))
>>    + geom_hline(yintercept=0)
>>
>> Or whatever you feel like doing.
>>
>> Roger
>>
>>>
>>> Cheers,
>>> Ben
>>>
>>>
>>>> spdep::plot.spcor
>>> function (x, main, ylab, ylim, ...)
>>> {
>>>    if (missing(main))
>>>        main <- x$var
>>>    if ((x$method == "I") || (x$method == "C")) {
>>>        lags <- as.integer(rownames(x$res))
>>>        to.plot <- which((x$res[, 3] > 0) & (x$res[, 3] != Inf))
>>>        sd2 <- rep(0, nrow(x$res))
>>>        sd2[to.plot] <- 2 * sqrt(x$res[to.plot, 3])
>>>        if (missing(ylim)) {
>>>            ylim <- range(c(x$res[, 1] + sd2, x$res[, 1] - sd2))
>>>        }
>>>        if (missing(ylab))
>>>            if (x$method == "I")
>>>                ylab <- "Moran's  I"
>>>        if (x$method == "C")
>>>            ylab <- "Geary's  C"
>>>        plot(lags, x$res[, 1], type = "p", pch = 18, ylim = ylim,
>>>            main = main, ylab = ylab, xaxt = "n")
>>>        arrows(lags, x$res[, 1] + sd2, lags, x$res[, 1] - sd2,
>>>            length = 0.1, angle = 90)
>>>        arrows(lags, x$res[, 1] - sd2, lags, x$res[, 1] + sd2,
>>>            length = 0.1, angle = 90)
>>>        axis(1, at = lags)
>>>        abline(h = x$res[1, 2])
>>>    }
>>>    else {
>>>        res <- as.vector(x$res)
>>>        lags <- as.integer(names(x$res))
>>>        if (missing(ylim))
>>>            ylim <- c(-1, 1)
>>>        if (missing(ylab))
>>>            ylab <- "Spatial autocorrelation"
>>>        plot(lags, res, type = "h", ylim = ylim, main = main,
>>>            ylab = ylab, lwd = 4, xaxt = "n")
>>>        axis(1, at = lags)
>>>        abline(h = 0)
>>>    }
>>> }
>>> <bytecode: 0x7fb8799d0e40>
>>> <environment: namespace:spdep>
>>>
>>>
>>>
>>>> On Mar 16, 2019, at 1:16 PM, Leonardo Matheus Servino <
>> leonardomservino using gmail.com> wrote:
>>>>
>>>> I tried the function par() and arguments inside the plot(), but some
>>>> parameters doesn't change.
>>>> For example, the argument pch=, which changes the symbols that
>> represents
>>>> the points in the plot doesn't work.
>>>>
>>>>
>>>> Em sáb, 16 de mar de 2019 às 13:48, Sarah Goslee <
>> sarah.goslee using gmail.com <mailto:sarah.goslee using gmail.com>>
>>>> escreveu:
>>>>
>>>>> Of course.
>>>>>
>>>>> The ... argument to the plot method means that you can use standard
>>>>> base graphics options to customize as you wish.
>>>>>
>>>>> ?par gives the whole list, although they may not all be useful for
>>>>> correlograms.
>>>>>
>>>>> If you have specific questions after you try customizing to your
>>>>> liking, the list can certainly help with details.
>>>>>
>>>>> Sarah
>>>>>
>>>>> On Sat, Mar 16, 2019 at 11:00 AM Leonardo Matheus Servino
>>>>> <leonardomservino using gmail.com> wrote:
>>>>>>
>>>>>> Hello,
>>>>>>
>>>>>> I've been tried to use the function "sp.correlogram". After plot the
>>>>>> correlogram, I would like to edit the grafic's appearence, to publish
>> it.
>>>>>> It is possible?
>>>>>>
>>>>>> Thanks
>>>>>>
>>>>>> --
>>>>>> Leonardo Matheus Servino
>>>>>> Pós-Graduação em Evolução e Diversidade
>>>>>> Universidade Federal do ABC - UFABC - Centro de Ciências Naturais e
>>>>> Humanas
>>>>>>
>>>>>
>>>>> --
>>>>> Sarah Goslee (she/her)
>>>>> http://www.numberwright.com
>>>>>
>>>>
>>>>
>>>> --
>>>> Leonardo Matheus Servino
>>>> Pós-Graduação em Evolução e Diversidade
>>>> Universidade Federal do ABC - UFABC - Centro de Ciências Naturais e
>> Humanas
>>>>
>>>> LED I - Laboratório de Evolução e Diversidade I - Bloco Delta, sala 202
>>>>
>>>> Rua Arcturus, 3. Jardim Antares
>>>> 09606-070 São Bernardo do Campo - SP
>>>>
>>>>      [[alternative HTML version deleted]]
>>>>
>>>> _______________________________________________
>>>> R-sig-Geo mailing list
>>>> R-sig-Geo using r-project.org <mailto:R-sig-Geo using r-project.org>
>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo <
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo>
>>> Ben Tupper
>>> Bigelow Laboratory for Ocean Sciences
>>> 60 Bigelow Drive, P.O. Box 380
>>> East Boothbay, Maine 04544
>>> http://www.bigelow.org
>>>
>>> Ecological Forecasting: https://eco.bigelow.org/
>>>
>>>
>>>
>>>
>>>
>>>
>>>       [[alternative HTML version deleted]]
>>>
>>> _______________________________________________
>>> R-sig-Geo mailing list
>>> R-sig-Geo using r-project.org
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>
>>
>> --
>> Roger Bivand
>> Department of Economics, Norwegian School of Economics,
>> Helleveien 30, N-5045 Bergen, Norway.
>> voice: +47 55 95 93 55; e-mail: Roger.Bivand using nhh.no
>> https://orcid.org/0000-0003-2392-6140
>> https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
>
>
>
>

-- 
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; e-mail: Roger.Bivand using nhh.no
https://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en


More information about the R-sig-Geo mailing list