-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinteractive_visualization.Rmd
More file actions
150 lines (123 loc) · 3.97 KB
/
interactive_visualization.Rmd
File metadata and controls
150 lines (123 loc) · 3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
---
title: "Interactive Visualizations"
author: "Aidi Bian"
date: "3/28/2019"
output: html_document
---
```{r}
library(shiny)
```
## Basic Button
```{r}
ui <- fluidPage(actionButton("goButton", "Wake up!"),
textOutput("reply"))
server <- function(input, output){
observeEvent(input, output)
output$reply<-renderText({"5 more minutes..."})
}
shinyApp(ui=ui, server=server)
```
## Random Histogram Generator
Now we will build another Shiny App one piece at a time (Only the code starting at line 97 will run). This app will generate a histogram based on random values drawn from a normal distribution, the user will be able to select the number of draws that generate the histogram by using a slider.
```{r}
ui <- fluidPage(
sliderInput(inputId = "num", label = "Choose a number",
value = 1, min = 1, max = 100), plotOutput("hist"))
server <- function(input, output) {
output$hist <- renderPlot({
hist(rnorm(input$num))
})
}
shinyApp(ui = ui, server = server)
```
## Final Project
Finally, build an interactive visualization using the data sets quiz-categories.csv and midterm-results.csv. These data represent midterm results from an open book test. The categories represent the skills required to answer each question:
wrangling - Question required data manipulations skills
coding - Question required coding skills
d.trees - Question invoilved decision trees
sna - Question involved social network analysis
nlp - Question involved natural language processing
viz - Question involved visualization of data
n.nets - Question involved neural nets
googleable - Question could be answered by searching the internet
non-googleable - Question could not be answered through simple searching of the internet
jitl - Question involved learning somethimg new (just in time learning)
substantive - Question involved wrestling with a complex idea that does not have a definitive answer
```{r}
midterm<-read.csv("midterm-results.csv", header = TRUE)
categories<-read.csv("quiz-categories.csv", header = TRUE)
```
```{r}
library(dplyr)
library(tidyr)
library(ggplot2)
df1<-gather(categories, Skill, Count, -Question)
df2<-df1[which(df1$Count==1),]
df2<-df2[,c(2,1)]
df2$Question<-as.factor(gsub("_c", "", df2$Question))
correct<-unlist(lapply(midterm[,3:32], sum))
nameCorrect<-paste("Q", seq(1:30), sep="")
correct_df<-data.frame(x=nameCorrect, y=correct)
colnames(correct_df)<-c("Question", "Correct_Number")
df3<-left_join(df2, correct_df, by="Question")
df4<-df3[,c(2,1,3)]
df5<-spread(df4, Skill, Correct_Number)
df5<-df5%>%arrange(as.factor(Question))
```
```{r}
ui<-fluidPage(
titlePanel("Skills"),
sidebarLayout(
sidebarPanel(
radioButtons("p", "Select a Skill: ",
list("wrangling"='k', "coding"='a', "d.trees"='b', "sna"='h',
"nlp"='f', "viz"='j', "n.nets"='e', "googleable"='c',
"non-googleable"='g', "jitl"='d', "substantive"='i'))
),
mainPanel(plotOutput("distPlot"))
)
)
server<-function(input, output){
output$distPlot<-renderPlot({
if(input$p=="a"){
i<-1
}
if(input$p=="b"){
i<-2
}
if(input$p=="c"){
i<-3
}
if(input$p=="d"){
i<-4
}
if(input$p=="e"){
i<-5
}
if(input$p=="f"){
i<-6
}
if(input$p=="g"){
i<-7
}
if(input$p=="h"){
i<-8
}
if(input$p=="i"){
i<-9
}
if(input$p=="j"){
i<-10
}
if(input$p=="k"){
i<-11
}
x<-df5%>%filter(!is.na(df5[,i+1]))%>%select(Question, i+1)
colnames(x)<-c("Question", "Number")
ggplot(x, aes(Question, Number))+
geom_col(color="pink", fill="blue")
})
}
shinyApp(ui=ui, server=server)
```
In this visualization, questions are clustered within skill categories. Some skill categories are more specific (such as wrangling, nlp, sna, d.trees), some are more general (such as coding, goolgeableable, non-googleable). We can see how many students get the questions related to specific skills right.