1 Exemplo Rstudio

1.1 Growth Quadrant

O Growth Quadrant oferece a oportunidade de ver o cenário competitivo dos principais participantes do setor. Dependendo da taxa de Crescimento de tráfego (eixo vertical) e o Volume de tráfego (eixo horizontal), a ferramenta divide os principais participantes do setor em quatro segmentos:

• Os “Leaders” executam bem sua visão atual e estão bem-posicionados para o futuro.

• Os “Visionaries” entendem para onde o mercado está indo ou têm uma visão para mudar as regras do mercado, mas ainda não executam bem. Podem ser startups, empresas investindo em crescimento de forma ativa ou grandes empresas entrando no mercado.

• Os “Niche Players” se concentram com sucesso em um pequeno segmento, ou estão desfocados e não inovam ou superam os outros.

• Os “Challengers” executam bem hoje ou podem dominar um grande segmento, mas não demonstram uma compreensão da direção do mercado.

1.2 Carregando Pacotes

Exemplos:

# Instalando Pacotes necessários.
install.packages("ggplot2")
install.packages("ggthemes")

# Carregando Pacotes.
library(ggplot2)
library(ggthemes)
# Carregando Pacotes.
library(ggplot2)
library(ggthemes)

1.3 Carregando DataSet

# Carregando DataSet Exemplo.
sample_dataset <- read.csv2("sample_human_development.csv")

paged_table(sample_dataset)
# Filtrando os 20 primeiros.
sample_dataset <- subset(sample_dataset, HDI_Rank <= 20)

paged_table(sample_dataset)

1.4 Verificando Classe dos dados.

# Verificando classe dos dados.
sapply(sample_dataset, class)
##        HDI_Rank         Country Life_Expectancy    Gross_Income 
##       "integer"     "character"     "character"       "integer"

1.5 Corrigindo coluna “Life_Expectancy” para numérico.

# Corrigindo coluna Life_Expectancy para numerico.
sample_dataset <- transform(
  sample_dataset, Life_Expectancy = as.numeric(Life_Expectancy)
  )

1.6 Verificando correção.

# Verificando classe dos dados.
sapply(sample_dataset, class)
##        HDI_Rank         Country Life_Expectancy    Gross_Income 
##       "integer"     "character"       "numeric"       "integer"

1.7 Calculando Média e Range dos Eixos.

# Calculando Renda Média.
med_GNI = mean(sample_dataset$Gross_Income)

print(med_GNI)
## [1] 46232.4
# Calculando Expectativa de Vida Média.
med_Life = mean(sample_dataset$Life_Expectancy)

print(med_Life)
## [1] 81.775
# Verificando range eixo X (Posicionar Texto).
x_GNI = range(sample_dataset$Gross_Income )

print(x_GNI)
## [1]  3389 79851
# Verificando range eixo Y (Posicionar Texto).
y_Life = range(sample_dataset$Life_Expectancy)

print(y_Life)
## [1] 79.1 84.0

1.8 Gerando Plot inicial primeira camada

# Gerando Plot.
library(ggplot2)

# Gerando Plot.
base <- ggplot()

base

1.9 Inserindo pontos

library(ggplot2)

# Gerando Plot.
base <- ggplot()

base + geom_point(data = sample_dataset, 
               aes(x = Gross_Income, y = Life_Expectancy))

1.10 Adicionando Tema e Título

library(ggplot2)

# Gerando Plot.
base <- ggplot(data = sample_dataset, 
               aes(x = Gross_Income, y = Life_Expectancy, 
                   color = Country)) + geom_point()

# Inserindo Tema e Título.
base + theme_classic() + ggtitle("Growth Quadrant")

1.11 Adicionando Rótulos nos pontos

library(ggplot2)

# Gerando Plot.
base <- ggplot(data = sample_dataset, 
               aes(x = Gross_Income, y = Life_Expectancy, 
                   color = Country)) + geom_point()

# Inserindo Tema e Título.
base + theme_classic() + ggtitle("Growth Quadrant") +
  
  # Posicionando texto dados.
  geom_label(aes(label = Country), hjust = .5, vjust = -.5) 

1.12 Ocultando Legenda Lateral

library(ggplot2)

# Gerando Plot.
base <- ggplot(data = sample_dataset, 
               aes(x = Gross_Income, y = Life_Expectancy, 
                   color = Country)) + geom_point()

  # Inserindo Tema e Título.
  base + theme_classic() + ggtitle("Growth Quadrant") +
  
  # Posicionando texto dados.
  geom_label(aes(label = Country), hjust = .5, vjust = -.5) +
    
  # Ocultando Legenda Lateral.
  theme(legend.position="none")

1.13 Inserindo linha média nos eixos

library(ggplot2)

# Gerando Plot.
base <- ggplot(data = sample_dataset, 
               aes(x = Gross_Income, y = Life_Expectancy, 
                   color = Country)) + geom_point()

  # Inserindo Tema e Título.
  base + theme_classic() + ggtitle("Growth Quadrant") +
  
  # Posicionando texto dados.
  geom_label(aes(label = Country), hjust = .5, vjust = -.5) +
    
  # Ocultando Legenda Lateral.
  theme(legend.position="none") +
  

  # Linha média eixo Y.
  geom_hline(yintercept = med_Life, linetype = "dashed", color = 'blue') +
  
  # Linha média eixo X.
  geom_vline(xintercept = med_GNI, linetype = "dashed", color = 'blue')

1.14 Inserindo Texto

library(ggplot2)

# Gerando Plot.
base <- ggplot(data = sample_dataset, 
               aes(x = Gross_Income, y = Life_Expectancy, 
                   color = Country)) + geom_point()

  # Inserindo Tema e Título.
  base + theme_classic() + ggtitle("Growth Quadrant") +
  
  # Posicionando texto dados.
  geom_label(aes(label = Country), hjust = .5, vjust = -.5) +
    
  # Ocultando Legenda Lateral.
  theme(legend.position="none") +
  

  # Linha média eixo Y.
  geom_hline(yintercept = med_Life, linetype = "dashed", color = 'blue') +
  
  # Linha média eixo X.
  geom_vline(xintercept = med_GNI, linetype = "dashed", color = 'blue') +
    
  # Inserindo e Posicionando texto "Niche Players".
  annotate("text", x = x_GNI[1], y = y_Life[1], label = "Niche Players", hjust = 0, vjust = 0, size = 6) +
  
  # Inserindo e Posicionando texto "Game Changers".
  annotate("text", x = x_GNI[1], y = y_Life[2], label = "Game Changers", hjust = 0, vjust = 0, size = 6) +
  
  # Inserindo e Posicionando texto "Leaders".
  annotate("text", x = x_GNI[2], y = y_Life[1], label = "Leaders", hjust = 1, vjust = 0, size = 6) +
  
  # Inserindo e Posicionando texto "Established Players".
  annotate("text", x = x_GNI[2], y = y_Life[2], label = "Established Players", hjust = 1, vjust = 0, size = 6)

2 Exemplo SAP Analytics Cloud

2.1 Exemplo Script R para SAP Analytics Cloud

library(ggplot2)

# Gerando Plot.
base <- ggplot(data = sample_dataset, 
               aes(x = Gross_Income, y = Life_Expectancy, 
                   color = Country)) + geom_point()

  # Inserindo Tema e Título.
  base + theme_classic() + ggtitle("Growth Quadrant") +
  
  # Posicionando texto dados.
  geom_label(aes(label = Country), hjust = .5, vjust = -.5) +
    
  # Ocultando Legenda Lateral.
  theme(legend.position="none") +
  

  # Linha média eixo Y.
  geom_hline(yintercept = med_Life, linetype = "dashed", color = 'blue') +
  
  # Linha média eixo X.
  geom_vline(xintercept = med_GNI, linetype = "dashed", color = 'blue') +
    
  # Inserindo e Posicionando texto "Niche Players".
  annotate("text", x = x_GNI[1], y = y_Life[1], label = "Niche Players", hjust = 0, vjust = 0, size = 6) +
  
  # Inserindo e Posicionando texto "Game Changers".
  annotate("text", x = x_GNI[1], y = y_Life[2], label = "Game Changers", hjust = 0, vjust = 0, size = 6) +
  
  # Inserindo e Posicionando texto "Leaders".
  annotate("text", x = x_GNI[2], y = y_Life[1], label = "Leaders", hjust = 1, vjust = 0, size = 6) +
  
  # Inserindo e Posicionando texto "Established Players".
  annotate("text", x = x_GNI[2], y = y_Life[2], label = "Established Players", hjust = 1, vjust = 0, size = 6)