-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.R
executable file
·149 lines (145 loc) · 5.74 KB
/
server.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
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
149
library(shiny)
library(dplyr)
library(ggplot2)
library(magrittr)
library(plotly)
load(".RData")
xaxis = list(range = c(-4.2, 3.4))
yaxis = list(range = c(-3.7, 4.5))
shinyServer(function(input, output) {
output$plot <- renderPlotly({
if (input$fargsattning == "Parti") {
parti_obj <-
joined_dataset %>% dplyr::filter(vald %in% input$vilka) %>% dplyr::filter(Parti %in% input$vilka2) %>%
ggplot(aes(
x = F1,
y = F2,
name = Namn,
color = get(input$fargsattning),
group = Parti
)) +
geom_point() +
scale_colour_manual(values = partycols) +
labs(x = "Vänster-Höger", y = "Grön-Alternativ-Liberal kontra Tradition-Auktoritet-Nationalist", color =
"") +
scale_y_continuous(breaks = NULL) +
scale_x_continuous(breaks = NULL) +
coord_fixed(ratio = 3 / 4)+theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),axis.text.x=element_blank(),
axis.ticks.x=element_blank(), axis.text.y=element_blank(),
axis.ticks.y=element_blank())
parti_obj <-
parti_obj %>% ggplotly(tooltip = c("name", "group")) %>% layout(
xaxis = xaxis,
yaxis = yaxis)
} else {
#höger-vänster
if (input$fargsattning == "Var någonstans skulle du placera dig själv på en politisk vänster-högerskala?") {
left_right_obj <-
joined_dataset %>% dplyr::filter(vald %in% input$vilka) %>% dplyr::filter(Parti %in% input$vilka2) %>%
dplyr::filter(
!is.na(
`Var någonstans skulle du placera dig själv på en politisk vänster-högerskala?`
)
) %>%
ggplot(aes(
x = F1,
y = F2,
color = get(input$fargsattning),
name = Namn,
group = Parti
)) +
geom_point() +
labs(x = "Vänster-Höger",
y = "Grön-Alternativ-Liberal kontra Tradition-Auktoritet-Nationalist",
color =
"") +
scale_y_continuous(breaks = NULL) +
scale_x_continuous(breaks = NULL) +
coord_fixed(ratio = 3 / 4) +
scale_colour_manual(values = leftrightcols)+theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),axis.text.x=element_blank(),
axis.ticks.x=element_blank(), axis.text.y=element_blank(),
axis.ticks.y=element_blank()) # red to blue
left_right_obj <-
left_right_obj %>% ggplotly(tooltip = c("name", "group"))%>% layout(
xaxis = xaxis,
yaxis = yaxis)
} else{
quest_obj <-
joined_dataset %>% dplyr::filter(vald %in% input$vilka) %>% dplyr::filter(Parti %in% input$vilka2) %>%
ggplot(aes(
x = F1,
y = F2,
color = get(input$fargsattning),
name = Namn,
group = Parti
)) +
geom_point() +
labs(x = "Vänster-Höger",
y = "Grön-Alternativ-Liberal kontra Tradition-Auktoritet-Nationalist",
color =
"") +
scale_y_continuous(breaks = NULL) +
scale_x_continuous(breaks = NULL) +
coord_fixed(ratio = 3 / 4) +
scale_colour_manual(values = questcols)+theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),axis.text.x=element_blank(),
axis.ticks.x=element_blank(), axis.text.y=element_blank(),
axis.ticks.y=element_blank()) # red to green
quest_obj <-
quest_obj %>% ggplotly(tooltip = c("name", "group"))%>% layout(
xaxis = xaxis,
yaxis = yaxis)
} #frågor
}
})
output$plot_parti <-
renderPlotly({
parti_means <-
joined_dataset %>% dplyr::filter(vald %in% input$vilka_parti) %>% dplyr::filter(Parti %in% input$vilka2_parti) %>%
ggplot(if(input$vad == 0){aes(
x = F1,
y = F2,
color = Parti,
group = Parti
)}else{aes(
x = F1,
y = F2,
name = Namn,
color = Parti,
group = Parti
)}
) +
scale_colour_manual(values = partycols) +
stat_ellipse() +
labs(x = "Vänster-Höger", y = "Grön-Alternativ-Liberal kontra Tradition-Auktoritet-Nationalist", color =
"") +
scale_y_continuous(breaks = NULL) +
scale_x_continuous(breaks = NULL) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),axis.text.x=element_blank(),
axis.ticks.x=element_blank(), axis.text.y=element_blank(),
axis.ticks.y=element_blank())+
coord_fixed(ratio = 3 / 4) +
if (input$vad == 0) {
geom_point(
aes(x = F1, y = F2),
data = (
joined_dataset %>% dplyr::filter(vald %in% input$vilka_parti) %>%
group_by(Parti) %>%
dplyr::summarise(F1 = mean(F1, na.rm=T),
F2 = mean(F2, na.rm=T)) %>% dplyr::filter(Parti %in% input$vilka2_parti)
)
)
} else{
geom_point()
}
parti_means <-
if (input$vad == 1) {
ggplotly(parti_means, tooltip = c("name", "group")) %>% layout(
xaxis = xaxis,
yaxis = yaxis)
} else{
ggplotly(parti_means, tooltip = c("group")) %>% layout(
xaxis = xaxis,
yaxis = yaxis)
}
})
})