Difference between revisions of "R/C2/Plotting-Histograms-and-Pie-Chart/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with " {| border =1 |'''Time''' |'''Narration''' |- || 00:01 || Welcome to the spoken tutorial on '''Plotting Histograms and Pie Chart. ''' |- || 00:08 || In this tutorial, we w...")
 
(No difference)

Latest revision as of 16:14, 22 May 2020


Time Narration
00:01 Welcome to the spoken tutorial on Plotting Histograms and Pie Chart.
00:08 In this tutorial, we will learn how to:
00:12 Plot histograms
00:15 Plot pie chart
00:18 Save plots
00:21 To understand this tutorial, you should know,
00:25 Data frames in R
00:28 Basics of Statistics
00:31 If not, please locate the relevant tutorials on R on this website.
00:39 This tutorial is recorded on
00:43 Ubuntu Linux OS version 16.04
00:48 R version 3.4.4
00:52 RStudio version 1.1.456
00:58 Install R version 3.2.0 or higher.
01:04 For this tutorial, we will use
01:07 A data frame moviesData.csv
01:12 A script file myPlots.R.
01:17 Please download these files from the Code files link of this tutorial.
01:24 I have downloaded and moved these files to Plots folder.
01:30 This folder is located in myProject folder on my Desktop.
01:36 I have also set this folder as my Working Directory.
01:42 Let us switch to Rstudio.
01:46 Open the script myPlots.R in RStudio.
01:52 Run this script by clicking on Source button.
01:58 movies data frame opens in the Source window.
02:03 This data frame has 600 rows and 31 columns.
02:09 It means this data frame has 600 observations of 31 variables.
02:17 To know about more this dataframe, please refer to the Additional Material section on this website.
02:25 In the Source window, scroll from left to right to see the remaining objects of movies data frame.
02:34 Now we will learn how to plot a histogram of the object named runtime in movies.
02:42 A histogram is
02:44 A visual representation of the distribution of a dataset.
02:49 Used to plot the frequency of score occurrences in a continuous dataset
02:56 Let us switch to RStudio.
02:59 Click on the script myPlots.R
03:04 In the Source window, type hist, within parentheses movies dollar sign runtime.
03:13 Save the script and run the current line by pressing Run button.
03:20 The histogram appears in the Plots window.
03:24 Click on Zoom to maximize this plot.
03:29 In the histogram there are 9 bins.
03:33 Height of a bin represents the number of observations lying in that interval.
03:40 Now, we will learn how to add labels to this histogram.
03:46 Also, we will change the color of bins in this histogram.
03:51 For this, we will add more arguments to the hist function.
03:56 Close the histogram.
03:59 In the Source window, type the following command.
04:04 Here, we have used the following arguments:
04:08 main for adding title to the histogram
04:12 xlab for adding label to the x axis
04:17 xlim to set the range of values on x axis
04:23 col to set the color of bins
04:28 Run the current line.
04:31 In the Files and Plots window, click on Zoom to maximize the plot.
04:38 The labels and the title of histogram have been changed.
04:44 We can observe that most of the movies have the runtime of around 75 to 125 minutes.
04:53 Now we will modify the number of breaks in the histogram.
04:58 We can make the groups finer or coarser by modifying the number of breaks.
05:05 Close this plot.
05:08 Let us add breaks argument in hist function and set it to 4.
05:15 In the Source window, type the following command.
05:20 Save the script and run the current line.
05:25 In the Files and Plots window, click on Zoom to maximize the plot.
05:31 Now, there are five bins in the histogram.
05:35 Remember we had set breaks to be 4.
05:40 Close the plot.
05:43 In the Source window, click on movies.
05:47 I am scrolling from right to left.
05:52 Now, we will learn how to create a pie chart from the object genre in the movies data frame.
06:00 A pie chart is
06:02 A circular chart.
06:04 Divided into wedge-like sectors, illustrating proportion.
06:10 The total value of the pie is always 100 percent.
06:15 Let us switch to RStudio.
06:18 First, we will make a table of the number of different genres.
06:24 For this, we use table function.
06:28 Click on the script myPlots.R
06:32 In the Source window, type the following command.
06:36 Run the last two lines.
06:40 We can see that there are 65 movies in Action & Adventure and 87 movies in Comedy.
06:49 Now, we draw a pie chart with genreCount.
06:54 Click on the script myPlots.R
06:58 In the Source window, type pie within parentheses genreCount.
07:05 Run the current line.
07:08 The pie chart appears in the Plots window.
07:12 Click on Zoom to maximize this pie chart.
07:17 We can see that Drama has largest share of movies.
07:23 Now, we will change the color of border in this pie chart.
07:28 For this, we will add more arguments to the pie function.
07:33 Cose this plot.
07:36 In the Source window, type the following command.
07:40 Save the script and run the current line.
07:45 The modified pie chart appears in the Plots window.
07:50 Click on Zoom to maximize the plot.
07:54 Now, we will learn how to save this pie chart as an image on our computer.
08:01 Close this plot.
08:03 I am resizing the Files and Plots window.
08:08 In the Plots window, click on Export.
08:12 From the drop-down menu, select Save as Image.
08:17 A window named Save Plot as Image appears.
08:22 You can select the format in which you want to save your image.
08:28 I am saving it in JPEG format.
08:33 Below the Image format option, you can select the directory where you want to save your image.
08:41 By default, RStudio will save the image in the directory where the script has been placed.
08:49 I will save the image in this folder.
08:53 Below the directory, in the field File name, you can write the name of the image to be saved.
09:03 I am saving the image with the name pieChart with capital C.
09:09 In the top right corner of this window, you can modify the dimensions of this image.
09:17 I am setting the width to 650.
09:21 Please make sure that Maintain aspect ratio is checked.
09:26 Below Maintain aspect ratio, click on Update Preview button.
09:32 The image with larger dimensions is shown.
09:37 Finally, click on Save.
09:41 I am resizing the Files and Plots window.


09:46 Now, click on the Files tab.
09:50 The image pieChart.jpeg has been saved in the Plots folder.
09:57 Click on this image to see the saved pie chart.
10:03 Let us summarize what we have learnt.
10:07 In this tutorial, we have learnt how to:
10:12 Plot histograms
10:15 Plot pie chart
10:18 Save plots
10:21 We now suggest an assignment.
10:25 Read the file moviesData.csv. Create a histogram of the object named imdb_num_votes in this file.
10:41 Create a pie chart of the object mpaa_rating.
10:48 Save both the plots.
10:51 The video at the following link summarises the Spoken Tutorial project.
10:56 Please download and watch it.
11:00 We conduct workshops using Spoken Tutorials and give certificates.
11:06 Please contact us.
11:09 Please post your timed queries in this forum.
11:14 Please post your general queries in this forum.
11:19 The FOSSEE team coordinates the TBC project.
11:23 For more details, please visit these sites.
11:27 The Spoken Tutorial project is funded by NMEICT, MHRD, Govt. of India
11:34 The script for this tutorial was contributed by Tushar Bajaj (TISS Mumbai).
11:42 This is Sudhakar Kumar from IIT Bombay signing off. Thanks for watching.

Contributors and Content Editors

Sakinashaikh