knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

youRtube

The goal of youRtube is to easily gather data and create visualizations from YouTube API data.

Installation

You can install the the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("rnevils/youRtube")
library(youRtube)

Getting Started

To use this package you need a YouTube API key. See here for how to get a key.

Save your API key as a string called "key" for easy use with the functions in the package

key <- "AIzaSyBAbuMv8NG47mox9ebPv9QWsuY9j3k2Ojd"
key = "AIzaSyA1sCzxpFiBw6SG16MsWPE872_W4XfMRlE"

Most Popular Videos Data

Use the function get_top_videos() to create a data frame of the current top trending videos on YouTube. You can specify which region and content category you are interested in.

Overall top trending videos in the US

top50_us <- get_top_videos(key, n = 50)

Top trending music videos in Great Britian

top10_uk_music <- get_top_videos(key, region = "United Kingdom", category = "Music")

Use get_region_list() and get_category_list() to see YouTube's regions and content categories.

head(get_region_list(key))
head(get_category_list(key, region = "Sweden"))

Use the function graph_top_videos_category() to see the overall top trending videos broken down by content category.

graph_top_videos_category(key, n = 25)
graph_top_videos_category(key, region = "United Kingdom", n = 25)

Word Cloud from Youtube Comments

use the make_cloud() function to create a word cloud of all the comments for a particular video.

In addition to the API key, make_cloud() also needs a Youtube video ID. To find the Id of a youtube video look at the url and find the last part after the v=

For example in https://www.youtube.com/watch?v=QjA5faZF1A8 the Id would be QjA5faZF1A8

key = "AIzaSyA1sCzxpFiBw6SG16MsWPE872_W4XfMRlE"
video_id = "QjA5faZF1A8"
make_cloud(key, video_id)

Sentiment analysis of YouTube Titles

Use get_top_titles() to returns a list of 200 titles from the most popular YouTube video pages using your API key.

api_key = "AIzaSyA1sCzxpFiBw6SG16MsWPE872_W4XfMRlE"
head(get_top_titles(api_key))

Use titles_sentiment_type_nrc() to generates a plot of the number of words that contribute to different sentiments in the top 200 YouTube titles using the NRC lexicon.

titles_sentiment_type_nrc(api_key)

Additionally, you can use titles_sentiment_contribution_bing() to generate a plot of the top 10 words that contribute to positive and negative sentiment in the top 200 YouTube titles using the Bing lexicon.

titles_sentiment_contribution_bing(api_key)

Word Cloud from YouTube Titles

Use make_top_title_word_cloud() to make a word cloud of 200 of the titles on YouTube's most popular videos. In addition to an API key, this function allows you to input custom parameters for the size, color and shape of the title word cloud. For more infomration on size, color and shape parameter options Wordcloud2.

make_top_title_word_cloud(api_key, size =1, color="random-light", shape = "circle")

an image caption Source: Wordcloud2 ouputs an interactive wordcloud of the top titles and counts; for reference, we've included a static image of the output.



rnevils/rpackage documentation built on May 12, 2020, 1:07 a.m.