partie Titouan
This commit is contained in:
parent
dd786495b4
commit
00919c2d5d
3 changed files with 52 additions and 4 deletions
Binary file not shown.
BIN
Les 10 genres les plus représentés.pdf
Normal file
BIN
Les 10 genres les plus représentés.pdf
Normal file
Binary file not shown.
56
main.R
56
main.R
|
@ -3,7 +3,7 @@ library("tidyverse")
|
|||
|
||||
|
||||
|
||||
data<-fromJSON("C:\\Users\\Marianne\\Desktop\\projet-analyse-exploratoire\\db_animes\\db_animes.json")
|
||||
data<-fromJSON(txt = "/home/labourde/Bureau/projet-analyse-exploratoire/db_animes/db_animes.json")
|
||||
dfAnimes <- as.data.frame(data)
|
||||
|
||||
#Filtrage des animes sortis avant 1960 (pas de télé :() et après 2021 et des OVAs, films, etc
|
||||
|
@ -29,10 +29,58 @@ dfAnimes %>%
|
|||
#Nettoyage des colonnes non utilisées
|
||||
dfAnimes <- select(dfAnimes, title, mean, rank, annee, saison, num_episodes, source, genres)
|
||||
|
||||
test <- dfAnimes
|
||||
####### Distribution des genres
|
||||
distributeGenres <- function(i){
|
||||
line <- as.data.frame(i$genres)
|
||||
line %>%
|
||||
rename(genres = 1) -> Genres
|
||||
i[ , !(names(dfAnimes) %in% c("genres"))] -> anime
|
||||
newdf <- cbind(anime, Genres)
|
||||
return(newdf)
|
||||
}
|
||||
|
||||
dfAnimesFinal <- data.frame(matrix(ncol = ncol(dfAnimes), nrow = 0))
|
||||
x <- names(dfAnimes)
|
||||
colnames(dfAnimesFinal) <- x
|
||||
dfAnimesFinal
|
||||
|
||||
for(i in 1:nrow(dfAnimes)) {
|
||||
row <- dfAnimes[i,]
|
||||
animeWithGenres <- distributeGenres(row)
|
||||
dfAnimesFinal <- rbind(dfAnimesFinal,animeWithGenres)
|
||||
}
|
||||
dfAnimesFinal
|
||||
|
||||
####### Plot the genre the most represented
|
||||
dfAnimesFinal %>%
|
||||
mutate(Nombre=sum(1)) %>%
|
||||
group_by(genres) %>%
|
||||
summarise(NombreGenre=sum(Nombre)) %>%
|
||||
arrange(desc(NombreGenre)) -> mostCommonGenre
|
||||
mostCommonGenre <- head(mostCommonGenre,10)
|
||||
ggplot(mostCommonGenre,aes(x=reorder(genres,NombreGenre),y=NombreGenre)) +
|
||||
geom_bar(stat='Identity',aes(fill=genres)) +
|
||||
labs(y="Occurence", x = "Genre") +
|
||||
ggtitle("Les 10 genres les plus représentés")
|
||||
|
||||
|
||||
####### Evolution des 5 genres les plus représentés sur les 5 dernières années
|
||||
dfAnimesFinal %>%
|
||||
filter(annee>1999) %>%
|
||||
mutate(Nombre=1) %>%
|
||||
group_by(genres,annee) %>%
|
||||
summarise(NombreGenre=sum(Nombre)) %>%
|
||||
arrange(desc(NombreGenre)) %>%
|
||||
group_by(annee) %>%
|
||||
slice_max(order_by = NombreGenre, n = 5) -> mostCommonGenrePast10Years
|
||||
ggplot(mostCommonGenrePast10Years,aes(x=annee,y=NombreGenre,color=genres)) +
|
||||
geom_point() +
|
||||
geom_line() +
|
||||
labs(y="Occurence", x = "Genre") +
|
||||
ggtitle("Evolution des 5 genres les plus représentés sur les 20 dernières années")
|
||||
|
||||
|
||||
|
||||
test %>%
|
||||
mutate(genres = paste(genres, collapse=",")) -> test
|
||||
|
||||
#Nombre d'animes durant plus de 2 cours (estimés à 30 épisodes) par an => a améliorer
|
||||
dfAnimes %>%
|
||||
|
|
Loading…
Reference in a new issue