#Carregando o pacote
library(ggplot2)
cores <- c("blue")
#O R é uma ferramenta poderosa quando voce usa os pacotes disponiveis #para executar as funções (chunk) voce tambem pode utilizar o comando clt+enter
#Gerando a massa de dados
setwd("D:\\3. ESTUDO\\PROTIFÓLIO\\R STUDIO")
arquivo <- "bdcolab.csv"
#read.csv(file.choose()) vamos nomear nossos dados
bdcolab <- read.csv(arquivo, header=TRUE, sep=";")
#view(bdcolab) posso usar depois de nomear meus dados para ver em formato tabela
colnames(bdcolab) <- c("anos","salario")
head(bdcolab)
## anos salario
## 1 8 64
## 2 3 57
## 3 9 30
## 4 3 72
## 5 6 43
## 6 13 43
#criando a visualização de dados
ggplot(data = bdcolab, aes(x = anos, y = salario)) +
geom_point(color = cores[1], size = 2) +
geom_smooth(method = "lm", color = "green4", size = 1) +
labs(title = "Tempo de empresa vs. salario",
x = "anos",
y = "salario em R$ (K)") +
theme_minimal() +
theme(panel.grid.major = element_line(color = "gray", size = 0.5),
panel.grid.minor = element_line(color = "lightgray", size = 0.25))
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning: The `size` argument of `element_line()` is deprecated as of ggplot2 3.4.0.
## ℹ Please use the `linewidth` argument instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `geom_smooth()` using formula = 'y ~ x'
#Criando a regressao
Regressao = lm( bdcolab$salario ~ bdcolab$anos )
Regressao$coefficients
## (Intercept) bdcolab$anos
## 40.277151 1.750742
#Analise exploratoria descritiva
summary(bdcolab)
## anos salario
## Min. : 1.000 Min. :20.00
## 1st Qu.: 3.000 1st Qu.:39.50
## Median : 8.000 Median :55.00
## Mean : 8.333 Mean :54.87
## 3rd Qu.:12.000 3rd Qu.:68.50
## Max. :21.000 Max. :90.00
#Valores dos coeficientes
Regressao$coefficients[1]
## (Intercept)
## 40.27715
Regressao$coefficients[2]
## bdcolab$anos
## 1.750742
ggplot(data = bdcolab, aes(x = anos, y = salario)) +
geom_point(color = cores[1], size = 2) +
geom_smooth(method = "lm", se = FALSE, color = "black", size = 1) +
labs(title = "Tempo de empresa vs. salario",
x = "anos",
y = "salario em R$ (K)") +
theme_minimal() +
theme(panel.grid.major = element_line(color = "gray", size = 0.5),
panel.grid.minor = element_line(color = "lightgray", size = 0.25))
## `geom_smooth()` using formula = 'y ~ x'
#Calculando o valor de Y com base no de X
TempoEmpresa = 3
y = Regressao$coefficients[1] + (TempoEmpresa * Regressao$coefficients[2])
#Apresentando o valor de y dado a apresentação dos anos
y
## (Intercept)
## 45.52938