Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(ggplot2)
- library(doParallel)
- cluster <- makeCluster(3)
- calcParticipationNumbers <- function(data) {
- data['megjelent_most'] <- NA
- data['megjelent_most_pct'] <- NA
- cities = foreach(c=unique(data$telepules), .combine=rbind) %dopar% {
- city_data <- data[data$telepules==c,]
- for (k in unique(city_data$id_k)) {
- tmp_k <- city_data[city_data$id_k == k,]
- tmp_k <- data.table(tmp_k)
- tmp_k[,megjelent_most := megjelent - c(0, megjelent[.I -1])]
- tmp_k$megjelent_most_pct <- tmp_k$megjelent_most / tmp_k$osszes * 100
- city_data[city_data$id_k == k,]$megjelent_most <- tmp_k$megjelent_most
- city_data[city_data$id_k == k,]$megjelent_most_pct <- tmp_k$megjelent_most_pct
- }
- data.frame(city_data)
- }
- cities
- }
- drawPlot <- function(city) {
- ggplot(test[test$telepules==city & test$id_ido != 8,], aes(x=id_ido, y=megjelent_most_pct)) + geom_point(alpha=.2) + geom_line(aes(group=korzet), alpha=.1) + theme_bw() + geom_smooth(aes(x=as.numeric(id_ido),y=megjelent_most_pct)) + xlab('Ido id') + ylab('Megjelent (%)') + ggtitle(city) + coord_cartesian(ylim=c(0,40))
- }
- tmp <- reszvetel_df[,c('telepules','id_k','osszes','megjelent','id_ido')]
- tmp$megjelent <- as.numeric(tmp$megjelent)
- tmp$osszes <- as.numeric(tmp$osszes)
- tmp$id_ido <- as.factor(tmp$id_ido)
- tmp['arany'] <- round(tmp$megjelent/tmp$osszes*100, 2)
- test <- calcParticipationNumbers(tmp)
- stopCluster(cluster)
- drawPlot('Sándorfalva')
Add Comment
Please, Sign In to add comment