|
@@ -7,6 +7,10 @@
|
|
|
# https://posit.co
|
|
# https://posit.co
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+# --------------------------------------------------------------------------
|
|
|
|
|
+# Slide 4, 5: Installing R
|
|
|
|
|
+# --------------------------------------------------------------------------
|
|
|
|
|
+
|
|
|
# Some samples
|
|
# Some samples
|
|
|
1 + 2
|
|
1 + 2
|
|
|
4 * 7
|
|
4 * 7
|
|
@@ -17,6 +21,22 @@
|
|
|
print("Hello World")
|
|
print("Hello World")
|
|
|
print("Hello World", quote=FALSE)
|
|
print("Hello World", quote=FALSE)
|
|
|
print(81 / 3)
|
|
print(81 / 3)
|
|
|
|
|
+q()
|
|
|
|
|
+
|
|
|
|
|
+# --------------------------------------------------------------------------
|
|
|
|
|
+# Slide 5: Installing R Studio
|
|
|
|
|
+# --------------------------------------------------------------------------
|
|
|
|
|
+1 + 2
|
|
|
|
|
+4 * 7
|
|
|
|
|
+print("Hello World")
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+# --------------------------------------------------------------------------
|
|
|
|
|
+# Slide 6: Running R on Posit Cloud
|
|
|
|
|
+# --------------------------------------------------------------------------
|
|
|
|
|
+1 + 2
|
|
|
|
|
+4 * 7
|
|
|
|
|
+print("Hello World")
|
|
|
|
|
|
|
|
# Some random values:
|
|
# Some random values:
|
|
|
rnorm(10)
|
|
rnorm(10)
|
|
@@ -107,6 +127,28 @@ plot(w, v)
|
|
|
plot(w, v, "l")
|
|
plot(w, v, "l")
|
|
|
help("plot")
|
|
help("plot")
|
|
|
|
|
|
|
|
|
|
+# --------------------------------------------------------------------------
|
|
|
|
|
+# Slide 8: Packages in R
|
|
|
|
|
+# --------------------------------------------------------------------------
|
|
|
|
|
+# Install needed package for plotting.
|
|
|
|
|
+# Needed only once after installing R
|
|
|
|
|
+install.packages("ggplot2")
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+# Activate "ggplot2" package.
|
|
|
|
|
+# Needed only once per session or script.
|
|
|
|
|
+library(ggplot2)
|
|
|
|
|
+
|
|
|
|
|
+qplot(data=iris, Sepal.Width, Sepal.Length)
|
|
|
|
|
+qplot(data=iris, Sepal.Width, Sepal.Length, colour=Species)
|
|
|
|
|
+qplot(data=iris, Sepal.Width, Sepal.Length, colour=Species, facets = .~ Species)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+qplot(data=diamonds, carat, price, colour=clarity, facets = . ~ clarity)
|
|
|
|
|
+
|
|
|
|
|
+# --------------------------------------------------------------------------
|
|
|
|
|
+# Slide 9: the daily life of a data scientist
|
|
|
|
|
+# --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
# Datasets
|
|
# Datasets
|
|
|
head(iris)
|
|
head(iris)
|
|
@@ -122,28 +164,12 @@ boxplot(iris$Sepal.Length ~ iris$Species)
|
|
|
plot(iris$Sepal.Width, iris$Sepal.Length)
|
|
plot(iris$Sepal.Width, iris$Sepal.Length)
|
|
|
|
|
|
|
|
|
|
|
|
|
-# Install needed package for plotting.
|
|
|
|
|
-# Needed only once after installing R
|
|
|
|
|
-install.packages("ggplot2")
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-# Activate "ggplot2" package.
|
|
|
|
|
-# Needed only once per session or script.
|
|
|
|
|
-library(ggplot2)
|
|
|
|
|
-
|
|
|
|
|
-qplot(data=iris, Sepal.Width, Sepal.Length)
|
|
|
|
|
-qplot(data=iris, Sepal.Width, Sepal.Length, colour=Species)
|
|
|
|
|
-qplot(data=iris, Sepal.Width, Sepal.Length, colour=Species, facets = .~ Species)
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
# Diamonds dataset
|
|
# Diamonds dataset
|
|
|
-
|
|
|
|
|
myData <- read.csv("diamonds.csv")
|
|
myData <- read.csv("diamonds.csv")
|
|
|
summary(myData)
|
|
summary(myData)
|
|
|
plot(myData$carat, myData$price)
|
|
plot(myData$carat, myData$price)
|
|
|
|
|
|
|
|
-qplot(data=diamonds, carat, price, colour=clarity, facets = . ~ clarity)
|
|
|
|
|
-
|
|
|
|
|
ggplot(data=myData, aes(x=carat, y=price)) + geom_point()
|
|
ggplot(data=myData, aes(x=carat, y=price)) + geom_point()
|
|
|
ggplot(data=myData, aes(x=carat, y=price, color=clarity)) + geom_point()
|
|
ggplot(data=myData, aes(x=carat, y=price, color=clarity)) + geom_point()
|
|
|
ggplot(data=myData[myData$carat < 2.5,], aes(x=carat, y=price, color=clarity)) + geom_point(alpha=0.1) + geom_smooth()
|
|
ggplot(data=myData[myData$carat < 2.5,], aes(x=carat, y=price, color=clarity)) + geom_point(alpha=0.1) + geom_smooth()
|