diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..6f2d247 Binary files /dev/null and b/.DS_Store differ diff --git a/exercise-1/.DS_Store b/exercise-1/.DS_Store new file mode 100644 index 0000000..6c51ab9 Binary files /dev/null and b/exercise-1/.DS_Store differ diff --git a/exercise-1/exercise.R b/exercise-1/exercise.R index 66c7fac..32123bd 100644 --- a/exercise-1/exercise.R +++ b/exercise-1/exercise.R @@ -1,9 +1,20 @@ # Exercise 1: Loading functions # Set your directory - +setwd('~/Desktop/Info/m18-shiny/') # Source your BuildScatter.r script, exposing your BuildScatter function - +source('./exercise-1/scripts/BuildScatter.R') # Use your BuildScatter function to draw a well labeled ggplot scatterplot of the iris data +library(ggplot2) + + +BuildScatter(data = iris, + xVar = 'Sepal.Length', + yVar = 'Sepal.Width', + colorVar = 'Species', + title = 'Iris Dataset', + xLab = 'Sepal Length', + yLab = 'Sepal Width' + ) \ No newline at end of file diff --git a/exercise-1/scripts/BuildScatter.R b/exercise-1/scripts/BuildScatter.R index 8ce59c6..d6ee536 100644 --- a/exercise-1/scripts/BuildScatter.R +++ b/exercise-1/scripts/BuildScatter.R @@ -8,3 +8,12 @@ # - Title of the plot (set a default of "Title") # - Label for the x axis (set a default of "X Title") # - Label for the y axis (set a default of "Y Title") + +library(ggplot2) +BuildScatter<- function(data, xVar, yVar, colorVar, title = "Title", xLab ="X title", yLab = "y title"){ + p<- ggplot(data = data) + + geom_point(mapping = aes(x = data[ ,xVar], y = data[ ,yVar], color = data[,colorVar])) + + labs(title = title, x = xLab, y = yLab) + + p +}