tests/eScatter.R

library(ECShiny)
library(tidyr)

# Dados simulados --
d <- data.frame(
  "Tempo" = sample(c(2001:2010),223,replace=TRUE),
  "Familia" = sample(LETTERS,223,replace=TRUE),
  "Consumo" = runif(223, min = 0, max = 100)*1e+02,
  "Renda" = runif(223, min = 0, max = 100)*1e+03,
  "Peso" = runif(223, min = 1, max = 43)*1e+02,
  "Cor" = runif(223, min = 1, max = 100)*1e+03,
  "Categoria" = sample(c("Alimentação","Vestuário"),223,replace=TRUE),
  stringsAsFactors=FALSE
)

eScatter(data=d,x="Renda",y="Consumo",name="Familia",
         size = "Peso",time="Tempo",
         xformat = list(prefix="R$"),
         yformat = list(prefix="R$"),
         sizeformat = list(prefix="R$"),
         print.json = TRUE)

eScatter(data=d,x="Renda",y="Consumo",name="Familia",
         time="Tempo",
         xformat = list(prefix="R$"),
         yformat = list(prefix="R$"),
         sizeformat = list(prefix="R$"),
         print.json = TRUE)

eScatter(data=d,x="Renda",y="Consumo",name="Familia",
         size = "Peso",time="Tempo",
         group = "Categoria",
         xformat = list(prefix="R$"),
         yformat = list(prefix="R$"),
         sizeformat = list(prefix="R$"),
         print.json = TRUE)

eScatter(data=d,x="Renda",y="Consumo",name="Familia",
         size = "Peso",
         xformat = list(prefix="R$"),
         yformat = list(prefix="R$"),
         sizeformat = list(prefix="R$"),
         print.json = TRUE)

eScatter(data=d,x="Renda",y="Consumo",name="Familia",
        xformat = list(prefix="R$",decimals=2),
         print.json = TRUE)

eScatter(data=d,x="Renda",y="Consumo",name="Familia",
         xformat = list(prefix="R$"),
         yformat = list(prefix="R$"),
         print.json = TRUE)



eScatter(data=d,x="Renda",y="Consumo",name="Familia",
         size = "Peso",
         group = "Categoria",
         xformat = list(prefix="R$"),
         yformat = list(prefix="R$"),
         sizeformat = list(prefix="R$"),
         print.json = TRUE)

eScatter(data=d,x="Renda",y="Consumo",name="Familia",
         color = "Cor",
         xformat = list(prefix="R$"),
         colorformat = list(prefix="R$"),
         print.json = TRUE)

eScatter(data=d,x="Renda",y="Consumo",name="Familia",
         color = "Cor",size = "Peso",
         xformat = list(prefix="R$"),
         sizeformat = list(prefix="R$"),
         print.json = TRUE)

eScatter(data=d,x="Renda",y="Consumo",name="Familia",
         group="Categoria",
         xformat = list(prefix="R$"),
         yformat = list(prefix="US$"),
         print.json = TRUE)


system.time(
eScatter(data=d,x="Renda",y="Consumo",name="Familia",
         time = "Tempo", group="Categoria",
         xformat = list(prefix="R$"),
         yformat = list(prefix="US$"),print.json = TRUE)
)

eScatter(data=d,x="Renda",y="Consumo",name="Familia",
         time = "Tempo",size="Peso",
         xformat = list(prefix="R$"),
         yformat = list(prefix="US$"),print.json = TRUE)

eScatter(data=d,x="Renda",y="Consumo",name="Familia",
         time = "Tempo",color="Peso",
         xformat = list(prefix="R$"),
         yformat = list(prefix="US$"),print.json = TRUE)

eScatter(data=d,x="Renda",y="Consumo",name="Familia",
         time = "Tempo",color="Peso",size="Cor",
         xformat = list(prefix="R$"),
         yformat = list(prefix="US$"),print.json = TRUE)


eScatter(data=filter(d,Tempo==2010),x="Renda",y="Consumo",name="Familia",
         color="Peso",size="Cor",
         xformat = list(prefix="R$"),
         yformat = list(prefix="US$"),print.json = TRUE)


eScatter(data=d,x="Renda",y="Consumo",name="Familia",
         time = "Tempo",group="Categoria",
         xformat = list(prefix="R$",decimals=2),
         yformat = list(prefix="US$"),
         print.json = TRUE)

eScatter(data=d,x="Renda",y="Consumo",name="Familia",
         time = "Tempo",
         xformat = list(prefix="R$"),
         yformat = list(prefix="US$"),
        timeline=list(data=c(2001:2002),start=2002))



library(dplyr)
td_base_dea <- readRDS("~/Dropbox/MARCO/produtos/eficiencia_combustivel/dados/td_base_dea.rds")
ta_dtb <- readRDS("~/Dropbox/MARCO/produtos/eficiencia_combustivel/dados/ta_Divisao_Territorial.rds")

d <- td_base_dea %>% ungroup %>%
  left_join(ta_dtb,by=c('cod_mundv', 'cod_mun'))

d <- d %>% group_by("Ano"=ano,"Código IBGE"=cod_mun,"Município"=nome_mun,
                    "Mesorregião"=nome_meso, "Microrregião"=nome_micro) %>%
  summarise(
    `Índice de Necessidades` = mean(need_index,na.rm=TRUE),
    `População`=mean(populacao, na.rm=TRUE),
    `Necessidades (log)` = log(`Índice de Necessidades` * `População`),
    `Despesas (log)` = log(mean(vl_gasto_real, na.rm=TRUE)

    )
  ) %>% as.data.frame

rotulo.mes<-c("Janeiro"=1, "Fevereiro"=2, "Março"=3, "Abril"=4, "Maio"=5, "Junho"=6,
              "Julho"=7, "Agosto"=8, "Setembro"=9, "Outubro"=10, "Novembro"=11, "Dezembro"=12)

rotulo.mes<- data.frame(Meses=rotulo.mes, nome_mes=names(rotulo.mes))

tempo<-td_base_dea %>%
  ungroup() %>%
  group_by(Ano=ano) %>%
  summarise(Meses=max(qtd_meses_tce, na.rm=TRUE))


d<-d %>%
  left_join(tempo, 'Ano')




eScatter(data=d,x="Necessidades (log)",
         y="Despesas (log)",name="Município",
         time = "Ano",group="Mesorregião",
         xformat = list(suffix="log",decimals=2),
         yformat = list(suffix="log",decimals=2),
         title = "Despesas x Necessidades com combustíveis"
)


eScatter(data=d,x="Necessidades (log)",
         y="Despesas (log)",name="Município",
         time = "Ano",
         xformat = list(decimals=2),
         yformat = list(decimals=2),
         title = "Despesas x Necessidades com combustíveis"
)







map <- list(name = 'pb',
            json = 'data-raw/pb_municipios_poligonos.json')

set.seed(132)
d <- data.frame(
  School = sample(c(0:9, letters, LETTERS), 100, replace=TRUE),
  lat = rnorm(100,mean=-7.137323,sd=0.22),
  lon = c(rnorm(50,mean=-34.8815975,sd=0.22)-0.7,
          rnorm(10,mean=-34.8815975,sd=0.22)-1.5,
          rnorm(40,mean=-34.8815975,sd=0.22)-3.2
          ),
  Students = runif(100, min = 10, max = 100),
  Scores = runif(100, min = 10, max = 400),
  Population = runif(100, min = 50, max = 800),
  "Category" = c(rep("A",70),rep("B",30))
)



echart(type="scatter",subtype="geo",data=d,x='School',y=c('lat','lon','Students'),
       map = map )

echart(type="scatter",subtype="geo",data=d,x='School',y=c('lat','lon','Students'),group = 'Category',
       map = map )


echart(type="scatter",subtype="geo",data=d,x='School',y=c('lat','lon','Students'),size='Scores',
       map = map )

echart(type="scatter",subtype="geo",data=d,x='School',y=c('lat','lon','Students'),size='Scores',
       map = map,group = 'Category' )



echart(type="scatter",subtype="geo",data=d,x='School',y=c('lat','lon','Students'),color='Population',
       map = map )

echart(type="scatter",subtype="geo",data=d,x='School',y=c('lat','lon','Students'),color='Population',
       map = map,group = 'Category' )

echart(type="scatter",subtype="geo",data=d,x='School',y=c('lat','lon','Students'),size='Scores',color='Population',
       map = map )


map <- list(name = 'usa',
            json = 'https://ecomfe.github.io/echarts-examples/public/data/asset/geo/USA.json')


set.seed(132)
d <- data.frame(
  School = sample(c(0:9, letters, LETTERS), 100, replace=TRUE),
  lat = rnorm(100,mean=39.5296501,sd=3.22),
  lon = c(rnorm(50,mean=-93.5326937,sd=2.22)+2.7,
          rnorm(10,mean=-93.5326937,sd=2.22)-2.5,
          rnorm(40,mean=-93.5326937,sd=3.22)-10.2
  ),
  Students = runif(100, min = 10, max = 100),
  Scores = runif(100, min = 10, max = 400),
  Population = runif(100, min = 50, max = 800)
)

echart(type="scatter",subtype="geo",data=d,x='School',y=c('lat','lon','Students'),
       map = map )

echart(type="scatter",subtype="geo",data=d,x='School',y=c('lat','lon','Students'),size='Scores',
       map = map )
lemaufpb/ECShiny documentation built on July 20, 2018, 3:37 p.m.