SQL
1
SELECT customer.first_name, customer.last_name, customer.email, COUNT(*) AS total_rentals
FROM customer
JOIN rental ON customer.customer_id = rental.customer_id
GROUP BY customer.first_name, customer.last_name, customer.email
ORDER BY total_rentals DESC
LIMIT 10;
2
SELECT film.title, film.description
FROM film
LEFT JOIN inventory ON film.film_id = inventory.film_id
LEFT JOIN rental ON inventory.inventory_id = rental.inventory_id
WHERE rental.rental_id IS NULL
GROUP BY film.title, film.description
ORDER BY film.title;
Displaying records 1 - 10
| ACADEMY DINOSAUR |
A Epic Drama of a Feminist And a Mad Scientist who must
Battle a Teacher in The Canadian Rockies |
| ALICE FANTASIA |
A Emotional Drama of a A Shark And a Database
Administrator who must Vanquish a Pioneer in Soviet Georgia |
| APOLLO TEEN |
A Action-Packed Reflection of a Crocodile And a
Explorer who must Find a Sumo Wrestler in An Abandoned Mine Shaft |
| ARGONAUTS TOWN |
A Emotional Epistle of a Forensic Psychologist And a
Butler who must Challenge a Waitress in An Abandoned Mine Shaft |
| ARK RIDGEMONT |
A Beautiful Yarn of a Pioneer And a Monkey who must
Pursue a Explorer in The Sahara Desert |
| ARSENIC INDEPENDENCE |
A Fanciful Documentary of a Mad Cow And a Womanizer who
must Find a Dentist in Berlin |
| BOONDOCK BALLROOM |
A Fateful Panorama of a Crocodile And a Boy who must
Defeat a Monkey in The Gulf of Mexico |
| BUTCH PANTHER |
A Lacklusture Yarn of a Feminist And a Database
Administrator who must Face a Hunter in New Orleans |
| CATCH AMISTAD |
A Boring Reflection of a Lumberjack And a Feminist who
must Discover a Woman in Nigeria |
| CHINATOWN GLADIATOR |
A Brilliant Panorama of a Technical Writer And a
Lumberjack who must Escape a Butler in Ancient India |
3
SELECT category.name AS category_name, AVG(film.length) AS average_length
FROM film
JOIN film_category ON film.film_id = film_category.film_id
JOIN category ON film_category.category_id = category.category_id
GROUP BY category.name
ORDER BY average_length DESC;
Displaying records 1 - 10
| Sports |
128.2027 |
| Games |
127.8361 |
| Foreign |
121.6986 |
| Drama |
120.8387 |
| Comedy |
115.8276 |
| Family |
114.7826 |
| Music |
113.6471 |
| Travel |
113.3158 |
| Horror |
112.4821 |
| Classics |
111.6667 |
4
SELECT actor.first_name, actor.last_name, COUNT(*) AS film_count
FROM actor
JOIN film_actor ON actor.actor_id = film_actor.actor_id
GROUP BY actor.first_name, actor.last_name
ORDER BY film_count DESC
LIMIT 5;
5 records
| SUSAN |
DAVIS |
54 |
| GINA |
DEGENERES |
42 |
| WALTER |
TORN |
41 |
| MARY |
KEITEL |
40 |
| MATTHEW |
CARREY |
39 |
5
SELECT DISTINCT customer.first_name, customer.last_name
FROM customer
JOIN rental ON customer.customer_id = rental.customer_id
JOIN inventory ON rental.inventory_id = inventory.inventory_id
JOIN film ON inventory.film_id = film.film_id
JOIN film_actor ON film.film_id = film_actor.film_id
JOIN actor ON film_actor.actor_id = actor.actor_id
WHERE actor.first_name = 'Johnny' AND actor.last_name = 'Depp';
6
SELECT film.title, SUM(payment.amount) AS total_revenue
FROM film
JOIN inventory ON film.film_id = inventory.film_id
JOIN rental ON inventory.inventory_id = rental.inventory_id
JOIN payment ON rental.rental_id = payment.rental_id
GROUP BY film.title
ORDER BY total_revenue DESC
LIMIT 10;
Displaying records 1 - 10
| TELEGRAPH VOYAGE |
231.73 |
| WIFE TURN |
223.69 |
| ZORRO ARK |
214.69 |
| GOODFELLAS SALUTE |
209.69 |
| SATURDAY LAMBS |
204.72 |
| TITANS JERK |
201.71 |
| TORQUE BOUND |
198.72 |
| HARRY IDAHO |
195.70 |
| INNOCENT USUAL |
191.74 |
| HUSTLER PARTY |
190.78 |
Plotly
1
library(plotly)
## Loading required package: ggplot2
##
## 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
library(ggplot2)
p<-ggplot(diamonds, aes(x = carat, y = price)) +
geom_point(aes(text = paste("Clarity:", clarity)), size = 1) +
ggtitle("Diamond Price vs Carat") +
xlab("Carat") +
ylab("Price")
## Warning in geom_point(aes(text = paste("Clarity:", clarity)), size = 1):
## Ignoring unknown aesthetics: text
plot_ly(diamonds, x = ~carat, y = ~price, type = 'scatter', mode = 'markers',
text = ~paste("Clarity:", clarity), marker = list(size = 10)) %>%
layout(title = "Diamond Price vs Carat",
xaxis = list(title = "Carat"),
yaxis = list(title = "Price"))
2
p
ggplot2 is based on the concept of graphic grammar, allowing plots to be
built layer by layer. It provides extensive customization options,
allowing for detailed control over a plot’s aesthetics, which is
especially useful for creating publication-quality static plots. It is
better suited for situations requiring high-quality, publication-ready
static plots, such as academic papers or professional reports.
Plotly, on the other hand, excels at creating interactive plots. Its
main feature is the ability to generate interactive visualizations, such
as zooming, panning, and viewing trends over time. Because of this
interactivity, Plotly is an excellent choice for web applications and
dashboards that emphasize user engagement and data exploration. Plotly
also supports a broader range of plot types, such as 3D plots and more
complex interactive charts, which ggplot2 does not support as
easily.
In conclusion, while ggplot2 is ideal for creating static, highly
customized plots for publications or reports, Plotly is a better choice
for interactive visualizations in web applications or for audiences who
benefit from an interactive data exploration experience.
3
library(gapminder)
library(plotly)
animated_plot<-plot_ly(gapminder, x = ~gdpPercap, y = ~lifeExp, size = ~pop, color = ~continent, text = ~country, frame = ~year,
marker = list(sizemode = "diameter")) %>%
layout(title = 'Global GDP per Capita vs Life Expectancy Over Time',
xaxis = list(title = 'GDP per Capita'),
yaxis = list(title = 'Life Expectancy')) %>%
animation_opts(frame = 100, redraw = TRUE)
animated_plot
## No trace type specified:
## Based on info supplied, a 'scatter' trace seems appropriate.
## Read more about this trace type -> https://plotly.com/r/reference/#scatter
## No scatter mode specifed:
## Setting the mode to markers
## Read more about this attribute -> https://plotly.com/r/reference/#scatter-mode
This animated plot provides a dynamic view of the relationship
between economic development and health outcomes across different
countries and over time. Each frame of the animation represents a year,
showing how countries’ GDP per capita and life expectancy have
changed.
The animation depicts a general trend in which countries experiencing
economic growth, as measured by an increase in GDP per capita,
frequently experience increases in life expectancy at the same time.
This pattern suggests a strong link between a country’s economic health
and its population’s physical health. As countries move rightward on the
plot (indicating economic growth), there is often a corresponding upward
movement (indicating increased life expectancy), emphasizing the impact
of economic prosperity on improving public health infrastructure, access
to medical care, and overall living conditions.