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
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.html linguist-detectable=false
*.Rmd linguist-language=R
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# Class Activity 2 - Introduction to Vizualization
# Introduction to Vizualization

This repo contains files for an in class activity (class activity 2) on data
visualisation using base R plotting functions for HUDK 4050: Core Methods in
Educational Data Mining.

HUDK 4050 is the first of three core courses in the Learning Analytics MS at
Teachers College, Columbia University focusing on the thinking, methods, and
conventions in data science. Particular attention is given to the fields of
Educational Data Mining and Learning Analytics. Refer to the
[Syllabus](https://github.com/timothyLeeXQ/HUDK-4050-Syllabus) (forked from
the [main repo](https://github.com/core-methods-in-edm/syllabus) which may
contain updates for future class iterations) for more information on HUDK 4050.

Other classes in the series are:
* [HUDK 4051: Learning Analytics:
Process and Theory](https://github.com/timothyLeeXQ/HUDK-4051-Syllabus) ([Main
repo](https://github.com/la-process-and-theory/syllabus))
* HUDK 5053: Feature Engineering Studio (Starting in May 2020.
[Main repo](https://github.com/feature-engineering-studio/syllabus))

## Instructor Notes
Introduction to Visualization using the Base R commands. Please fork and clone this repo and open the .Rmd file for further instructions.
50 changes: 33 additions & 17 deletions class-activity-2.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ D2 <- filter(D1, schoolyear == 20112012)

#Histograms
```{r}
#Generate a histogramof the percentage of free/reduced lunch students (frl_percent) at each school
#Generate a histogram of the percentage of free/reduced lunch students (frl_percent) at each school

hist()
hist(D2$frl_percent)

#Change the number of breaks to 100, do you get the same impression?

hist(D2$frl_percent, breaks = 100)

#Yes. Both histograms show negative skew with most data around 80% of students with free/reduced lunch.

#Cut the y-axis off at 30

hist(D2$frl_percent, breaks = 100, ylim = c(0,30))
Expand All @@ -31,8 +33,6 @@ hist(D2$frl_percent, breaks = 100, ylim = c(0,30))

hist(D2$frl_percent, breaks = c(0,10,20,80,100))



```

#Plots
Expand Down Expand Up @@ -76,25 +76,33 @@ pairs(D5)
1. Create a simulated data set containing 100 students, each with a score from 1-100 representing performance in an educational game. The scores should tend to cluster around 75. Also, each student should be given a classification that reflects one of four interest groups: sport, music, nature, literature.

```{r}
#rnorm(100, 75, 15) creates a random sample with a mean of 75 and standard deviation of 20
#rnorm(100, 75, 15) creates a random sample with a mean of 75 and standard deviation of 15
#pmax sets a maximum value, pmin sets a minimum value
#round rounds numbers to whole number values
#sample draws a random samples from the groups vector according to a uniform distribution


studentPerformance = rnorm(100, 75, 15)
studentPerformance[studentPerformance > 100] = 100

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an another way of setting maximum and minimum values with a single line of code. round(pmax(1, pmin(100, rnorm(n=100, mean=75, sd=15))))

studentPerformance[studentPerformance < 1] = 1
studentPerformance = round(studentPerformance)
studentInterest = sample(c("sport", "music", "nature", "literature"), size = 100, replace = TRUE)
studentData = data.frame(id = c(1:100), studentPerformance, studentInterest)
```

2. Using base R commands, draw a histogram of the scores. Change the breaks in your histogram until you think they best represent your data.

```{r}

hist(studentData$studentPerformance, breaks = 8)
```


3. Create a new variable that groups the scores according to the breaks in your histogram.

```{r}
#cut() divides the range of scores into intervals and codes the values in scores according to which interval they fall. We use a vector called `letters` as the labels, `letters` is a vector made up of the letters of the alphabet.
letters = c("F", "E", "D", "C", "B", "A")
studentGrade = cut(studentData$studentPerformance,
breaks = c(40, 50, 60, 70, 80, 90, 100),
labels = letters)
studentData = cbind(studentData, studentGrade)

```

Expand All @@ -106,47 +114,55 @@ library(RColorBrewer)

#The top section of palettes are sequential, the middle section are qualitative, and the lower section are diverging.
#Make RColorBrewer palette available to R and assign to your bins
histColourPalette = brewer.pal(7, "OrRd")

#Use named palette in histogram

hist(studentData$studentPerformance, breaks = 8, col = histColourPalette)
```


5. Create a boxplot that visualizes the scores for each interest group and color each interest group a different color.

```{r}
#Make a vector of the colors from RColorBrewer

boxColourPalette = brewer.pal(4, "Spectral")
boxplot(studentData$studentPerformance ~ studentData$studentInterest, col = boxColourPalette)
```


6. Now simulate a new variable that describes the number of logins that students made to the educational game. They should vary from 1-25.

```{r}

logins = sample(c(1:25), size = 100, replace = TRUE)
studentData = cbind(studentData, logins)
```

7. Plot the relationships between logins and scores. Give the plot a title and color the dots according to interest group.

```{r}

plot(studentData$studentPerformance, studentData$logins,
main = "Plot of Logins against scores",
xlab = "Student Scores",
ylab = "Student Logins",
col = studentData$studentInterest,
pch=19)

```


8. R contains several inbuilt data sets, one of these in called AirPassengers. Plot a line graph of the the airline passengers over time using this data set.

```{r}

plot(AirPassengers, type = "l")
```


9. Using another inbuilt data set, iris, plot the relationships between all of the variables in the data set. Which of these relationships is it appropraiet to run a correlation on?

```{r}

pairs(iris)
```

10. Finally use the knitr function to generate an html document from your work. If you have time, try to change some of the output using different commands from the RMarkdown cheat sheet.

*I presume this just means press "knit"?*

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another way: render("nameofthefile.Rmd", output_format="html_document")


11. Commit, Push and Pull Request your work back to the main branch of the repository

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job overall!

570 changes: 570 additions & 0 deletions class-activity-2.html

Large diffs are not rendered by default.