The best way to start manipulating a list of top best IMDB movies in R is to install a package called jrTidyverse (see a full description). To install and load the package into R, use the following codes:
library(remotes)
remotes::install_github("jr-packages/jrTidyverse")
## Skipping install of 'jrTidyverse' from a github remote, the SHA1 (8e02670c) has not changed since last install.
## Use `force = TRUE` to force installation
library(jrTidyverse)
Now use can load the top 10 (for example) movies based on the audience rates given in IMDB.COM into R easily and quickly. Use the below codes for doing this:
data(movies)
movies10 <- movies[1:10,]
movies10
## # A tibble: 10 x 21
## title year budget gross duration classification votes rating language
## <chr> <dbl> <dbl> <dbl> <dbl> <chr> <dbl> <dbl> <chr>
## 1 Avatar 2009 2.37e8 7.61e8 178 12A 8.86e5 7.9 English
## 2 Pirates o~ 2007 3 e8 3.09e8 169 12A 4.71e5 7.1 English
## 3 Spectre 2015 2.45e8 2.00e8 148 12A 2.76e5 6.8 English
## 4 The Dark ~ 2012 2.5 e8 4.48e8 164 12A 1.14e6 8.5 English
## 5 John Cart~ 2012 2.64e8 7.31e7 132 12A 2.12e5 6.6 English
## 6 Spider-Ma~ 2007 2.58e8 3.37e8 156 12A 3.83e5 6.2 English
## 7 Tangled 2010 2.6 e8 2.01e8 100 PG 2.95e5 7.8 English
## 8 Avengers:~ 2015 2.5 e8 4.59e8 141 12A 4.63e5 7.5 English
## 9 Harry Pot~ 2009 2.5 e8 3.02e8 153 PG 3.22e5 7.5 English
## 10 Batman v ~ 2016 2.5 e8 3.30e8 183 12A 3.72e5 6.9 English
## # ... with 12 more variables: country <chr>, cast_total_facebook_likes <dbl>,
## # action <dbl>, adventure <dbl>, fantasy <dbl>, sci_fi <dbl>, thriller <dbl>,
## # romance <dbl>, comedy <dbl>, other <dbl>, drama <dbl>, crime <dbl>
In order to visualize the top 10 movies as mentioned above, we are going to do some interesting trick and use different types of colors. That is why, I am going to take a detour and introduce a fantastic package to make the visualization more fun. Color palettes have always been famous among all graphical experts and here we want to pick some of them to use in our ggplot. To see the difference we are going to plot a simple ggplot and then apply the package and see the difference that it makes.
To do a simple and ordinary visualization, all you need to do is to use ggplot2 and jrTidyverse altogether:
library(ggplot2)
ggplot(data=movies10, aes(y=reorder(title,rating), x=rating)) +
geom_bar(stat="identity", fill="steelblue")+
geom_text(aes(label=rating), hjust=1.2, size=4.9, col='yellow')+
theme_minimal()+
labs(title = "Top 10 Movies in IMDB.com",y = "",x = "IMDB Rate")+
annotate("text", x = 2, y = 1, label = "@RStudio_ir", col='white', size=4)+
theme(axis.text.x = element_text(color = "grey20", size = 12, angle = 0, hjust = .5, vjust = .5),
axis.text.y = element_text(color = 'darkgreen', size = 10, angle = 0, hjust = 1, vjust = 0),
axis.title.x = element_text(color = "red", size = 12, angle = 0, hjust = .5, vjust = 0),
axis.title.y = element_text(color = 'darkgreen', size = 12, angle = 90, hjust = .5, vjust = .5, face = "plain"))
To do a simple and ordinary visualization, all you need to do is to use ggplot2 and jrTidyverse altogether:But we are not done yet! let’s make it a little bit fun. Next, I am going to introduce a package called **feathers** (click to see the description). To install and load the package, use the following codes:
devtools::install_github("shandiya/feathers")
## Skipping install of 'feathers' from a github remote, the SHA1 (71bd3dbf) has not changed since last install.
## Use `force = TRUE` to force installation
library(feathers)
Color palettes are stored in this package as a list called feathers_palettes. These palettes are inspired by a number of Australian Birds. We are going to choose the following bird:
Olive-backed Oriole (Oriolus sagittatus)
This bird is called Olive-backed Oriole (Oriolus sagittatus) and the color palette inspired by this beautiful creature is created like this:
So let’s dive in and visualize the same plot using these colors:
ggplot(data=movies10, aes(y=reorder(title,rating), x=rating)) +
geom_bar(stat="identity", fill=get_pal("oriole"),col=get_pal("oriole"))+
geom_text(aes(label=rating), hjust=1.2, size=4.9, col='yellow')+
theme_minimal()+
labs(title = "Top 10 Movies in IMDB.com",y = "",x = "IMDB Rate")+
annotate("text", x = 2, y = 1, label = "@RStudio_ir", col='white', size=4)+
theme(axis.text.x = element_text(color = "grey20", size = 12, angle = 0, hjust = .5, vjust = .5),
axis.text.y = element_text(color = 'darkgreen', size = 10, angle = 0, hjust = 1, vjust = 0),
axis.title.x = element_text(color = "red", size = 12, angle = 0, hjust = .5, vjust = 0),
axis.title.y = element_text(color = get_pal("oriole"), size = 12, angle = 90, hjust = .5, vjust = .5, face = "plain"))
## Warning: Vectorized input to `element_text()` is not officially supported.
## Results may be unexpected or may change in future versions of ggplot2.
Colors are one of the main pillars of every visualization. Don’t ignore it and always try to improvise the colors using trick like this one. Colors that you choose from the nature have a wonderful characteristic of being all matched together. Thanks for reading this.