This week I thought it was interesting diving into all of the possible graphs that are offered by ggplot2. To explore these I will use the ccm2 dataset that we have used for the two previous assignments.

library(tidyverse)
## Loading tidyverse: ggplot2
## Loading tidyverse: tibble
## Loading tidyverse: tidyr
## Loading tidyverse: readr
## Loading tidyverse: purrr
## Loading tidyverse: dplyr
## Conflicts with tidy packages ----------------------------------------------
## filter(): dplyr, stats
## lag():    dplyr, stats
load("C:/Users/Samuel.Bradford/Desktop/ccm.rdata")

ccm2 <- ccm %>%
  select(num_critic_for_reviews, director_facebook_likes, actor_1_facebook_likes, gross, genres, movie_title, num_voted_users, cast_total_facebook_likes, num_user_for_reviews, language, country, content_rating, budget, title_year, imdb_score, movie_facebook_likes) %>%
  mutate(ratio = gross/budget) %>%
  filter(content_rating == "PG"| content_rating == "G" | content_rating == "GP" | content_rating == "R") -> ccm2

I will take the dataset ccm2 and apply a density plot and histogram to the data. In addition, we will then make variations to the graphs using a couple useful tools.

g1 = ggplot(ccm2, aes(gross)) + geom_density()

g2 = ggplot(ccm2, aes(gross)) + geom_histogram()

g1

g2
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

As you can see, the data is skewed to the left and tells us a lot of information, but, if, for example, the data was so left or right skewed that you data became useless, you could use log10 scaling to help with making the data manageable. By adding a log10 scaling to the x-axis we can more clearly look at the data within this dataset.

g3 = ggplot(ccm2, aes(gross)) + geom_density() + scale_x_log10()

g4 = ggplot(ccm2, aes(gross)) + geom_histogram() + scale_x_log10()

g3

g4
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

All in all, ggplot2 has alot of useful tools that we can use to better display and use data. The varying types of graphs really leaves the selectioni of which one to use up to the individual and the individual’s situation.