[R] How to read a shapefile with areas other than the one used by default in the spplot?

2020-03-25 Thread Yana Borges
Hello!
I send the same question I asked in the stackoverflow, if you don't mind.
It is possible that it is something simple, but I really did not succeed.

I need to make a map as it is in the script I send below. The shapefile I
am using, as well as the data, are attached.
My problem: I want the divisions by Regional Health (RS), and not by
municipality, which are 399. There are 22 Health Regionals, but I can't
identify them on the map. In the shp file there is this subdivision, but I
was unable to insert it that way.
How do I read by RS and not by municipality (default)?

I used the packages ggplot2, factoextra and rgdal

Thank you!

prec <- readxl::read_xlsx('Cluster\\municipios.xlsx', sheet =
"Obito0a6dias2",col_names = T)
tard <- readxl::read_xlsx('Cluster\\municipios.xlsx', sheet =
"Obito7a27dias2",col_names = T)
pop <- readxl::read_xlsx('Cluster\\municipios.xlsx', sheet =
"pop2",col_names = T)
# TAXAS
taxa.prec <- data.frame(prec[1:22,2:18]/pop[1:22,2:18]*1000,row.names
= prec$mun)
taxa.tard <- data.frame(tard[1:22,2:18]/pop[1:22,2:18]*1000,row.names
= prec$mun)
`# head(taxa.prec)
### Dados ##
txp <- txt  <- res.hc  <- grupo  <- list()
dados <- taxa.grupos <- plot <- list()
for (i in 1:ncol(taxa.prec)) {
txp[[i]]<- scale(taxa.prec[,i])
txt[[i]]<- scale(taxa.tard[,i])
res.hc[[i]] <- hclust(dist(data.frame(txp[[i]],
txt[[i]],
row.names = prec$mun)),
method = "ward.D2")
grupo[[i]]  <- cutree(res.hc[[i]], k = 4)
dados[[i]]  <- data.frame(RS = 1:22,taxap = taxa.prec[,i],
taxat = taxa.tard[,i],
Grupo=factor(grupo[[i]]),
row.names = prec$mun)
taxa.grupos[[i]] <- aggregate(cbind(taxap, taxat) ~ grupo[[i]],
dados[[i]], mean)
taxa.grupos[[i]]$media.pt <- apply(taxa.grupos[[i]][2:3], 1, mean)}
names(dados) <- 2000:2016

mapa <- maptools::readShapePoly('Cluster\\PR\\rs_pr\\RS.shp')

gp <- list(gp1=list(),gp2=list(),gp3=list(),gp4=list())for (i in 1:17) {
 for (j in 1:4) {
 gp$gp1[[i]] <- which(dados[[i]]$Grupo == 1)
 gp$gp2[[i]] <- which(dados[[i]]$Grupo == 2)
 gp$gp3[[i]] <- which(dados[[i]]$Grupo == 3)
 gp$gp4[[i]] <- which(dados[[i]]$Grupo == 4) }}

aux <- matrix(0, ncol=17, nrow=399)
for (i in 1:17) {for (j in 1:4) {
aux[,i][mapa$RS %in% gp[[j]][[i]]] <- taxa.grupos[[i]]$media.pt[j]}}
mapa@data[6:22] <- aux

 # Mapas em cores
corDegrade <- colorRampPalette(c("#99", "orange","red", "darkred"))
x11()spplot(mapa, zcol=c(6:22), col.regions =corDegrade(16),
   layout(matrix(c(1:20),nrow = 5,ncol = 4, byrow = TRUE)),
   names.attr = c(2000:2016))
__
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] How to read a shapefile with areas other than the one used by default in the spplot?

2020-03-25 Thread Bert Gunter
1. Wrong list. You should post on r-sig-geo instead.

2. As you use ggplot, why aren't you using ggmap() ?

Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )

On Wed, Mar 25, 2020 at 6:34 AM Yana Borges  wrote:
>
> Hello!
> I send the same question I asked in the stackoverflow, if you don't mind.
> It is possible that it is something simple, but I really did not succeed.
>
> I need to make a map as it is in the script I send below. The shapefile I
> am using, as well as the data, are attached.
> My problem: I want the divisions by Regional Health (RS), and not by
> municipality, which are 399. There are 22 Health Regionals, but I can't
> identify them on the map. In the shp file there is this subdivision, but I
> was unable to insert it that way.
> How do I read by RS and not by municipality (default)?
>
> I used the packages ggplot2, factoextra and rgdal
>
> Thank you!
>
> prec <- readxl::read_xlsx('Cluster\\municipios.xlsx', sheet =
> "Obito0a6dias2",col_names = T)
> tard <- readxl::read_xlsx('Cluster\\municipios.xlsx', sheet =
> "Obito7a27dias2",col_names = T)
> pop <- readxl::read_xlsx('Cluster\\municipios.xlsx', sheet =
> "pop2",col_names = T)
> # TAXAS
> taxa.prec <- data.frame(prec[1:22,2:18]/pop[1:22,2:18]*1000,row.names
> = prec$mun)
> taxa.tard <- data.frame(tard[1:22,2:18]/pop[1:22,2:18]*1000,row.names
> = prec$mun)
> `# head(taxa.prec)
> ### Dados ##
> txp <- txt  <- res.hc  <- grupo  <- list()
> dados <- taxa.grupos <- plot <- list()
> for (i in 1:ncol(taxa.prec)) {
> txp[[i]]<- scale(taxa.prec[,i])
> txt[[i]]<- scale(taxa.tard[,i])
> res.hc[[i]] <- hclust(dist(data.frame(txp[[i]],
> txt[[i]],
> row.names = prec$mun)),
> method = "ward.D2")
> grupo[[i]]  <- cutree(res.hc[[i]], k = 4)
> dados[[i]]  <- data.frame(RS = 1:22,taxap = taxa.prec[,i],
> taxat = taxa.tard[,i],
> Grupo=factor(grupo[[i]]),
> row.names = prec$mun)
> taxa.grupos[[i]] <- aggregate(cbind(taxap, taxat) ~ grupo[[i]],
> dados[[i]], mean)
> taxa.grupos[[i]]$media.pt <- apply(taxa.grupos[[i]][2:3], 1, mean)}
> names(dados) <- 2000:2016
>
> mapa <- maptools::readShapePoly('Cluster\\PR\\rs_pr\\RS.shp')
>
> gp <- list(gp1=list(),gp2=list(),gp3=list(),gp4=list())for (i in 1:17) {
>  for (j in 1:4) {
>  gp$gp1[[i]] <- which(dados[[i]]$Grupo == 1)
>  gp$gp2[[i]] <- which(dados[[i]]$Grupo == 2)
>  gp$gp3[[i]] <- which(dados[[i]]$Grupo == 3)
>  gp$gp4[[i]] <- which(dados[[i]]$Grupo == 4) }}
>
> aux <- matrix(0, ncol=17, nrow=399)
> for (i in 1:17) {for (j in 1:4) {
> aux[,i][mapa$RS %in% gp[[j]][[i]]] <- taxa.grupos[[i]]$media.pt[j]}}
> mapa@data[6:22] <- aux
>
>  # Mapas em cores
> corDegrade <- colorRampPalette(c("#99", "orange","red", "darkred"))
> x11()spplot(mapa, zcol=c(6:22), col.regions =corDegrade(16),
>layout(matrix(c(1:20),nrow = 5,ncol = 4, byrow = TRUE)),
>names.attr = c(2000:2016))
> __
> 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.


[R] RODBC Multiple Results

2020-03-25 Thread Doran, Harold
I'm calling a stored procedure that returns multiple tables and my current 
framework uses RODBC and sqlQuery() to communicate between R and the databases 
we connect to. A new stored procedure returns multiple tables and I found this 
on SO indicating that RODBC "may not" be able to retrieve multiple tables.

https://stackoverflow.com/questions/41494419/how-to-read-multiple-result-sets-returned-from-a-sql-server-stored-procedure-in

I'd very much like to continue within the structure of code I have using RODBC, 
so am asking if RODBC in fact *cannot* retrieve multiple tables as noted in the 
SO responses or if anyone has insight on how it might be feasible within the 
context of RODBC using  sqlQuery()?

Thanks
Harold


[[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] Changing mu in svyttest for one sample test

2020-03-25 Thread Mavra Ahmed
Hi All,

I am doing a one-sample t-test for survey data with replicates (svrepdesign).
I was wondering if there is a way to change the mu in svyttest for one sample 
test? I can't find a way to do this online for svyttest but I was able to do it 
for ttest.
for example; in the following, I can change the mu to be a known standard (in 
this case, 15):
ttest(dataset$outcome, mu=15)

For svyttest, I can only do as follows:
svyttest(outcome~0, dataset)
svyttest(outcome~1,dataset)
but I want to test my mean against a known standard (e.g. 15 as in the above 
case) using svyttest. Is there a way to do this? If not, what would be another 
way to test this?

Thanks for your help,
Mavra



[[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] RODBC Multiple Results

2020-03-25 Thread Bert Gunter
You might wish to post this on r-sig-db if you do not get a
satisfactory reply here.

Also, have you checked the databases task view on :
https://cran.r-project.org/ ?

Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )

On Wed, Mar 25, 2020 at 9:54 AM Doran, Harold  wrote:
>
> I'm calling a stored procedure that returns multiple tables and my current 
> framework uses RODBC and sqlQuery() to communicate between R and the 
> databases we connect to. A new stored procedure returns multiple tables and I 
> found this on SO indicating that RODBC "may not" be able to retrieve multiple 
> tables.
>
> https://stackoverflow.com/questions/41494419/how-to-read-multiple-result-sets-returned-from-a-sql-server-stored-procedure-in
>
> I'd very much like to continue within the structure of code I have using 
> RODBC, so am asking if RODBC in fact *cannot* retrieve multiple tables as 
> noted in the SO responses or if anyone has insight on how it might be 
> feasible within the context of RODBC using  sqlQuery()?
>
> Thanks
> Harold
>
>
> [[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.