(In this article we have goals to have some fun with basic web-scraping the top 50 anime from the web) (Source: Myanimelist)
(You can convert the file in csv format with “write.csv” command)
library(rvest)
## Warning: package 'rvest' was built under R version 4.0.3
## Loading required package: xml2
## Warning: package 'xml2' was built under R version 4.0.3
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.0.3
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
link="https://myanimelist.net/topanime.php"
page = read_html(link)
Titles = page %>% html_nodes(".anime_ranking_h3 a")%>%html_text()
Rating = page %>% html_nodes(".on.score-label")%>%html_text()
Extra = page %>% html_nodes(".mt4 , .score-8")%>%html_text()
df<-data.frame(Titles,Rating)
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.0.3
library(plotly)
## Warning: package 'plotly' was built under R version 4.0.3
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
p<-ggplot(df,aes(Rating,Titles))+geom_point()+theme(legend.key.height= unit(1000000, "cm"),axis.text.x = element_text(size= 7,angle=45,,hjust = 9),axis.text.y = element_text(size= 7,color="Blue",hjust = 2),axis.title=element_text(size=5))
#Lets make it little bit interactive
ggplotly(p,width = 900,height = 1000)
Made by: Harsh Trivedi ##Packages used: {rvest,dplyr,ggplot2,plotly}