How to Modify and Customize Plots in R | R Tutorial 2.9 | MarinStatsLectures

MarinStatsLectures-R Programming & Statistics
10 Aug 201315:15
EducationalLearning
32 Likes 10 Comments

TLDRIn this instructional video, Mike Marin offers a comprehensive guide on customizing R plots, focusing on scatterplots using Lung Capacity Data. He explains how to modify plot elements such as character size, fonts, colors, and plotting symbols, and demonstrates adding regression lines and distinguishing between genders. The tutorial also covers advanced techniques like splitting the plot screen for comparative visualization and customizing axis labels for clarity. Marin encourages viewers to explore the 'par' command for further customization options.

Takeaways
  • πŸ“ˆ The video by Mike Marin focuses on modifying R plots, specifically scatterplots using the Lung Capacity Data.
  • πŸ” The 'par' command in R can be explored in the Help menu to understand various plotting parameters that can be adjusted.
  • πŸ“ The 'cex' argument changes the size of the plotting characters, with different variations like 'cex.main', 'cex.lab', and 'cex.axis' for title, labels, and axis values respectively.
  • 🎨 The 'col' argument is used to change the color of various plot elements, including the title, labels, and axis.
  • πŸ–Œ The 'font' argument allows for changing the font style of the title, labels, and axis text, with options like italic and bold.
  • πŸ“Š The 'pch' argument is used to change the plotting character, which can be a number for standard symbols or a specific character.
  • πŸ“‰ The 'abline' function can add a regression line to the plot, and its appearance can be customized with 'col', 'lty', and 'lwd' arguments.
  • πŸ‘¦πŸ»πŸ‘§πŸ» Differentiating between genders in a plot can be achieved by using distinct colors and plotting characters, such as blue 'M' for males and pink 'F' for females.
  • πŸ–ΌοΈ The 'mfrow' or 'mfcol' arguments can be used to create multiple plots on a single screen, allowing for side-by-side or row-wise comparisons.
  • βœ‚οΈ The 'axes' argument set to FALSE in the plot command can remove axis labels, enabling custom axis labeling with the 'axis' command.
  • πŸ“ The 'box' command can add a border around the plot for a cleaner and more organized appearance.
Q & A
  • What is the main focus of Mike Marin's video?

    -The video focuses on modifying plots produced using R, specifically discussing changes that can be applied to scatterplots for simplicity.

  • Which dataset does Mike Marin use for demonstrating plot modifications in R?

    -Mike Marin uses the Lung Capacity Data for demonstrating the modifications in R plots.

  • What is the 'par' command in R used for?

    -The 'par' command in R is used to set various plotting parameters that can be changed to customize the appearance of plots.

  • How can one change the size of the plotting characters in a scatterplot in R?

    -The size of the plotting characters can be changed using the 'cex' argument in R.

  • What arguments can be used to alter the size of the title, x and y labels, and axis values in a plot?

    -The arguments 'cex.main', 'cex.lab', and 'cex.axis' can be used to alter the size of the title, x and y labels, and axis values respectively.

  • How can the fonts in different parts of a plot be changed in R?

    -Fonts can be changed using the 'font.main', 'font.lab', and 'font.axis' arguments to specify the font style for the title, labels, and axis text.

  • What is the purpose of the 'col' argument in R when modifying plots?

    -The 'col' argument is used to change the color of various elements in a plot, such as the plotting characters, title, labels, and axis.

  • What does the 'pch' argument do in R when creating a scatterplot?

    -The 'pch' argument is used to change the plotting character, allowing the user to select a specific symbol or number to represent data points in a scatterplot.

  • How can a regression line be added to a scatterplot in R?

    -A regression line can be added to a scatterplot using the 'abline' function in R, which can also be customized with color, line type, and width arguments.

  • What is the purpose of the 'mfrow' and 'mfcol' arguments in R when creating multiple plots?

    -The 'mfrow' and 'mfcol' arguments in R are used to split the plotting screen into multiple rows and columns, allowing for the display of multiple plots on a single screen.

  • How can axis labels be customized or specific values included on the x or y-axis in R plots?

    -Axis labels can be customized using the 'axis' command in R, where the user specifies the positions and labels they want to appear on the x or y-axis.

  • What command can be used to add a box around a plot in R to make it look neater?

    -The 'box' command can be used in R to add a box around a plot, improving its visual appearance.

  • How can one learn more about the different plotting parameters that can be changed in R?

    -To learn more about the different plotting parameters, one can explore the Help menu for the 'par' command in R or use a question mark (?) in front of the command.

Outlines
00:00
πŸ“Š Customizing R Plots with Basic Aesthetics

In this segment, Mike Marin introduces viewers to the customization of plots in R, focusing on a scatterplot for simplicity. He discusses modifying plot elements such as character size using 'cex', title size with 'cex.main', axis labels with 'cex.lab', and axis values with 'cex.axis'. Additionally, he covers changing fonts for the title, labels, and axis using 'font.main', 'font.lab', and 'font.axis'. The paragraph also touches on altering plot colors using arguments like 'col', 'col.main', 'col.lab', and 'col.axis'. The demonstration aims to show the variety of changes possible, even though using too many colors is not recommended for clarity in plots.

05:03
πŸ” Advanced Plot Customization in R

This paragraph delves into more advanced customization techniques for R plots. Mike explains how to add a regression line to the scatterplot using 'abline' and customize its color, type, and width with 'col', 'lty', and 'lwd'. He also discusses differentiating plot points by gender, using distinct colors and plotting characters, and how to re-label axes with 'xlab' and 'ylab'. The paragraph further explores the addition of multiple data sets to a plot without overwriting and the use of 'mfrow' or 'mfcol' to create multiple plots on a single screen. Mike emphasizes the importance of setting comparable x and y limits for side-by-side plots and concludes with the idea of relabeling axes for clarity.

10:07
πŸ“ˆ Fine-Tuning Plot Axes and Aesthetics in R

The final paragraph focuses on the fine-tuning of plot axes and overall aesthetics. Mike begins by resetting the plotting screen and then demonstrates how to selectively display axis values, such as showing only specific ages on the x-axis or including the mean age as a label. He explains the use of the 'axes' argument set to FALSE to remove default axis labels and then re-introduce them with the 'axis' command, specifying positions and labels. Additionally, Mike shows how to add a box around the plot for a neater appearance using the 'box' command. He also mentions the possibility of placing labels on the right side of the plot for y-axis values. The paragraph concludes with a reminder that while many customization options are available, it's essential to maintain plot clarity and not overcomplicate the presentation.

Mindmap
Keywords
πŸ’‘R
R is a programming language and environment for statistical computing and graphics. It is widely used for data analysis and visualization. In the context of the video, R is the primary tool used to modify and create scatterplots, demonstrating its capabilities for data visualization.
πŸ’‘Scatterplot
A scatterplot is a type of plot that displays the values of two variables for a set of data. Each data point is represented by a dot positioned at the corresponding values of the variables. In the video, the scatterplot is the main focus, used to compare 'Age' to 'Height' and to demonstrate various modifications.
πŸ’‘Lung Capacity Data
The Lung Capacity Data is a dataset used in the video series, which likely contains information about individuals' lung capacities along with other variables such as age and height. The video uses this data to create and modify scatterplots.
πŸ’‘par
In R, 'par' is a function that controls graphical parameters. It can be used to set various aspects of a plot, such as margins, character expansion, and line types. The video script mentions exploring the 'par' function to see all the different plotting parameters that can be changed.
πŸ’‘cex
The 'cex' argument in R is used to change the size of plotting characters, such as points, text, and lines. In the script, 'cex' is used to adjust the size of the plotting characters to half of the original size by setting it to 0.5.
πŸ’‘Font
Font refers to the visual appearance of text, including typeface and size. In the video, different 'font' arguments are used to change the style of the title, labels, and axis text, such as 'font.main' for the title and 'font.lab' for labels.
πŸ’‘Color
Color is used to differentiate elements in a plot and to enhance visual appeal. The script discusses changing colors of various plot elements using arguments like 'col', 'col.main', 'col.lab', and 'col.axis'.
πŸ’‘pch
The 'pch' argument in R specifies the plotting character to be used for points in a plot. It can be a number or a specific character. The video uses 'pch' to change the plotting character to a triangle or the letter 'W'.
πŸ’‘abline
The 'abline' function in R is used to add straight lines to a plot, such as a regression line. In the script, 'abline' is used to add a linear model to predict 'Height' using 'Age', and its appearance can be modified with 'col', 'lty', and 'lwd' arguments.
πŸ’‘mfrow and mfcol
In R, 'mfrow' and 'mfcol' are parameters used to arrange multiple plots on a single device. 'mfrow' arranges plots in rows, while 'mfcol' arranges them in columns. The video script mentions using these to create side-by-side plots for comparison.
πŸ’‘Axis
An axis in a plot provides a scale for the data. The script discusses modifying axis labels and limits, such as using 'xlab' and 'ylab' to change axis labels, and setting specific values to appear on the axes.
πŸ’‘Box
In the context of the video, 'box' refers to adding a border around the plot area. The 'box' command is used to create a neat and tidy appearance for the final plot.
Highlights

Introduction to modifying R plots with a focus on scatterplots for simplicity.

Use of the 'par' command to explore various plotting parameters.

Importing and attaching Lung Capacity Data for demonstration.

Adjusting the size of plotting characters with the 'cex' argument.

Changing the title size with 'cex.main' for a more prominent display.

Modifying x and y label sizes using 'cex.lab' for better readability.

Altering axis value sizes with 'cex.axis' to fit plot aesthetics.

Changing fonts for the title, labels, and axis with 'font' arguments.

Demonstration of color changes in plot elements using 'col' arguments.

Customizing plotting characters with 'pch' for unique data point representations.

Adding a linear regression line to the scatterplot with 'abline'.

Adjusting line type and width for emphasis on the regression line.

Differentiating genders in the same plot with distinct colors and characters.

Re-labeling axes for clarity and better data representation.

Adding multiple points to a plot without overwriting existing data.

Creating separate plots for different groups using 'mfrow' or 'mfcol'.

Setting consistent x and y limits for comparable multi-plot displays.

Relabeling axes with custom values and labels for specific analysis.

Adding a box around the plot for a cleaner and more professional look.

Exploring further customization options in the 'par' command for advanced plotting.

Transcripts
Rate This

5.0 / 5 (0 votes)

Thanks for rating: