Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Binary file added exercise-1/.DS_Store
Binary file not shown.
15 changes: 13 additions & 2 deletions exercise-1/exercise.R
Original file line number Diff line number Diff line change
@@ -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'
)
9 changes: 9 additions & 0 deletions exercise-1/scripts/BuildScatter.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}