-
Notifications
You must be signed in to change notification settings - Fork 1
/
linked_scatter.R
77 lines (65 loc) · 2.44 KB
/
linked_scatter.R
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
yearChoices <- c("2019" = 2019,
"2018" = 2018,
"2017" = 2017,
"2016" = 2016,
"2015" = 2015,
"2014" = 2014,
"2013" = 2013,
"2012" = 2012,
"2011" = 2011,
"2010" = 2010,
"2009" = 2009,
"2008" = 2008)
plotChoices = c("Temperature" = "temperature",
"Dew Point" = "dew.point",
"Humidity" = "humidity",
"Pressure" = "pressure",
"Wind Speed Mean" = "wind.speed.mean",
"Wind Bearing Mean" = "wind.bearing.mean",
"Time" = "ds")
linkedScatterUI <- function(id) {
ns <- NS(id)
fluidRow(
column(6, plotOutput(ns("plot1"), brush = ns("brush"))),
column(6, plotOutput(ns("plot2"), brush = ns("brush"))),
column(12, selectInput("advYear",
strong("Choose year"),
choices = yearChoices,
selected = "2019")),
column(6, selectInput("selectLeftX",
strong("Choose left plot x variable"),
choices = plotChoices,
selected = "humidity"),
selectInput("selectLeftY",
strong("Choose left plot y variable"),
choices = plotChoices,
selected = "temperature")),
column(6, selectInput("selectRightX",
strong("Choose right plot x variable"),
choices = plotChoices,
selected = "dew.point"),
selectInput("selectRightY",
strong("Choose right plot y variable"),
choices = plotChoices,
selected = "temperature"))
)
}
linkedScatter <- function(input, output, session, data, left, right) {
# Yields the data frame with an additional column "selected_"
# that indicates whether that observation is brushed
dataWithSelection <- reactive({
brushedPoints(data(), input$brush, allRows = TRUE)
})
output$plot1 <- renderPlot({
scatterPlot(dataWithSelection(), left())
})
output$plot2 <- renderPlot({
scatterPlot(dataWithSelection(), right())
})
return(dataWithSelection)
}
scatterPlot <- function(data, cols) {
ggplot(data, aes_string(x = cols[1], y = cols[2])) +
geom_point(aes(color = selected_)) +
scale_color_manual(values = c("black", "#66D65C"), guide = FALSE)
}