Data Science Academy - R Fundamentos

Download: http://github.com/dsacademybr

Esses são alguns exemplos simples do que pode ser feito com a linguagem R. O curso completo está disponível em:

http://www.datascienceacademy.com.br/pages/curso-r-fundamentos-para-analise-de-dados


In [5]:
# Carregando os pacotes
library(datasets)
library(broom)
library(ggplot2)
library(lattice)
library(QuantPsyc)

In [7]:
# Visualizando o dataset
data(iris)
str(iris)
head(iris)


'data.frame':	150 obs. of  5 variables:
 $ Sepal.Length: num  5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
 $ Sepal.Width : num  3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
 $ Petal.Length: num  1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
 $ Petal.Width : num  0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
 $ Species     : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
Out[7]:
Sepal.LengthSepal.WidthPetal.LengthPetal.WidthSpecies
15.1 3.5 1.4 0.2 setosa
24.9 3 1.4 0.2 setosa
34.7 3.2 1.3 0.2 setosa
44.6 3.1 1.5 0.2 setosa
55 3.6 1.4 0.2 setosa
65.4 3.9 1.7 0.4 setosa

In [9]:
# Regressão Linear Simples
# Sepal Length vs Petal Lenth
ggplot(data = iris,aes(x = Sepal.Length, y = Petal.Length)) +
  geom_point(size = 2, colour = "black") +
  geom_point(size = 1, colour = "white") +
  geom_smooth(aes(colour = "black"), method = 'lm') +
  ggtitle("Sepal Length vs Petal Length") +
  xlab("Sepal Length") + ylab("Petal Length") +
  theme(legend.position = "none")


Fim

Obrigado - Data Science Academy - facebook.com/dsacademybr