📱

Get Our Mobile App

Take your business learning on the go!

Download on the App StoreGet it on Google Play

Data Analysis with R Programming Complete Course | Data Analytics

My Lesson3:32:53

Transcription

Hey there, data pro. You've come a long way since the beginning of your learning journey. Congratulations on your accomplishment! Just think of all the skills you've learned along the way. You now know how to use structured thinking to define a problem and ask the right questions; work with spreadsheets, databases, and tools like SQL to organize and transform data; clean your data to make sure it has integrity before you analyze it; create impactful visuals to illustrate key points; and craft a compelling story to communicate insights to stakeholders. That's an impressive list of skills, but we're not done yet. Your skill set's about to get even bigger. In this course, you'll learn about a new concept called programming and how you can use the R programming language to analyze your data.

By now, you know that the data analysis process includes six phases: ask, prepare, process, analyze, share, and act. Now we'll learn all about the R programming language and how it can help you in each phase of the process. When you're done, you'll be presented with an optional case study. The case study will give you the chance to solve a data analysis problem using all the skills you've learned in this program. You'll find out more about this project later on. Okay, let's talk about computer programming.

Computer programming refers to giving instructions to a computer to perform an action or set of actions. You can use different programming languages to write these instructions. You might choose a specific language based on the project you want to pursue or the problem you want to solve. The R programming language is super useful for organizing, cleaning, and analyzing data. If this is your first experience with computer programming, welcome! When I first started learning about data analysis, I didn't have a background in programming either. In fact, before I fell in love with data, I was trained as an opera singer. I also have a lot of friends that came into this field from the arts and learned about programming later in their career. R is a great place to start learning.

R for the first time can be challenging and even more empowering. A lot of the skills you've learned in this program will help you learn basic programming concepts. Take it one step at a time and go at your own pace. And just like in previous videos, you'll start with the basics and move forward from there. You've tackled tough challenges before, and you always come out on top. You've got this!

Let me introduce myself. My name's Carrie. I work as a research manager at Google. I lead a team that researches the best way to improve the performance of people in organizations. In other words, I help people work better and work smarter and help organizations function in a healthy and productive way. I first learned R as a junior data analyst while I was working on a multi-year project about virtual work. We were looking at data on people's virtual work experiences and trying to understand how working remotely impacts performance. It was a complex project with a lot of data to sift through. I kept encountering problems and searching for better and faster ways to do things. This is when I became aware of the power of R. Whenever I got stuck, I'd learn a little more about R and discover a solution to my problem. I soon realized that R could help me do almost anything involving data, even better and faster than I thought possible. Fortunately, there are tons of great online resources for R and a super supportive online community. If I had a question, I'd go online and find the answer. As the project progressed, I was able to learn more and more and become a much more effective data analyst. My teammates even started coming to me for advice about R. Realizing that I could continue to learn my skills at any stage in my career was an empowering experience. Learning R unlocked my ability to perform data analysis at the highest level.

In your future career as a data analyst, you'll have the opportunity to continually learn and grow. To me, that might be one of the coolest aspects of the job, and learning R is one of the most rewarding parts of that growth process. I'm still learning new ways to use R all the time. Plus, you can apply these skills to other programming languages like Python, Julia, or JavaScript. There's no limit to how far you can go with programming. It even goes beyond data analysis. After I learned R, I found myself thinking about all kinds of projects I could use programming for, both at work and for fun. It opens up a whole new world of possibilities.

Now let's talk about what you're about to learn. We'll start off with an introduction to programming languages. Then we'll take a closer look at R itself and explore its main features and functions. We'll also cover some basic programming concepts and learn how to use them effectively in R. Next, we'll learn how to work with data in R. You'll discover how R can supercharge your data analysis skills and let you clean, transform, visualize, and report data in new and more powerful ways. Learning R will help you take your data analysis to the next level. It'll also look great on your resume. R is widely recognized as a key credential in entry-level job positions. Knowing how to use R will give you a big boost in your job hunt and will help you stand out as a new analyst. Coming up, we'll talk more about programming languages in general and how they can help you analyze your data. After that, we'll jump right into R. Before you know it, you'll be using R to power your data analysis.

Hi, great to see you again! When I first learned R, it was the visuals that really got me hooked. I still think it's so cool that you can write a little bit of code, press a button, and presto—out pops an awesome data visualization. Before we get into all of the details, I thought it would be fun to give you a quick sneak peek and show you what R can do. What follows will be a preview of what you're going to learn. By the end of this course, you'll not only understand all this code, you'll be able to write and execute it as well. For now, just sit back, relax, and enjoy the show.

Let's start by loading a library and getting a data set to work with. We can use the Palmer Penguins dataset, which contains size measurements for three penguin species that live on the Palmer Archipelago in Antarctica. This includes data on stuff like body mass, flipper length, and bill length. The data set has 344 rows of information sorted into eight columns. The Palmer Penguins data is popular with analysts and is great for fun exploration, visualization, and teaching concepts. We'll see more of this data set later on in the course. Let's say we want to visualize the relationship between body mass and flipper length. You may guess the larger the penguin, the longer the flipper. We can find out for sure by creating a plot. Let's make a scatter plot. A scatter plot uses points to display the relationship between two variables. So the two variables we're going to compare are body mass and flipper length. No need to memorize all these details right now; you'll have time to learn more about them later on.

Let's check out the parts of this code and how they fit together. The first function starts the plot. If we run the code at this point, all we get is a blank plot. If we add some more code, R will put labels on each axis of our plot and add lines for data. Body mass is on the y-axis, and flipper length is on the x-axis, but the data points are not yet visible. To get the complete plot, we can add some more code that tells R how to represent our data. For example, we could use points, bars, or lines. We'll use points to create a scatter plot. We can go further; for example, we can change how the plot looks. Let's change the color of all of the points to purple. You can hit the up arrow to pull up the last piece of code you ran, so we'll do that now, and then we'll add in `color = purple` inside `geom_point`. Now we can hit enter to run this. We can also add new information to the plot and use color to highlight it. Let's tell R to assign a different color to each species of penguin. This way, we can link data points to each group of penguins. Gentoos are the largest. The legend, just to the right of the plot, shows us that the blue points refer to the Gentoos. R automatically creates a legend for the plot to help us understand the color coding. R does everything you tell it to do and even does stuff you don't ask for—it's just that helpful. We can also use shape to highlight the different penguin species, or we can use both color and shape. In addition to highlighting our data, we can also reorganize it. We can break our data down into smaller groups or subsets and create a plot for each subset. Let's say we want to focus on the data for each species. Facet functions let us create a separate plot for each species. Check this out! Facets are so great. We can even put text on our plot to point to specific data or communicate a message. Let's give our plot a title to clearly indicate its purpose. Finally, we can save our plot so we can access or share it later on. Now, if we click on the files tab, we'll find our file in the list. Let's open it up.

Well, that's the end of the show. I hope you enjoyed it as much as I did. We were able to take a big data set and quickly visualize some significant patterns. These are some of the basic functions in R. In other words, this is just the beginning. It's exciting to think of all the ways R can help you realize the full power of data analysis. As you move forward, you'll learn more about each of the functions we use to create our plots. By the end of this course, you'll be the one writing and executing all of this code. Coming up, we'll learn more about computer programming and how it can help you analyze your data. See you soon!

The advice I would give to someone just learning R is that mistakes are part of the process. Errors and error messages are part of the process. When I think about the people who are even better than I am at R, I think I've come to realize they're not necessarily smarter than I am, but they may be a little bit more persistent and delving a little bit deeper. And certainly, compared to when I started, I think initially I'd see an error message and think I did it wrong—like, oh, you know, game over. And now it's like, oh, that's just part of the game. When I started to get a little bit of exposure to what R looked like, I was like, oh, that seems too sophisticated; it seems like it probably is really, really hard. But the people who used it that I had met were always really enthusiastic about it, and they felt like it had so many advantages over other software that you can use for running analyses. There were a lot of times before I used R where I might use spreadsheets or some other tool, and I would kind of be trying to hack at what really needed to happen. Sometimes I was using multiple tools because an individual tool couldn't really do all of what I wanted it to do, but it's sort of like I knew in my mind, and yet it wasn't totally fluid, the execution of it. The more exposure I've gotten to R, the more I realized a lot of what I would try to do that way I can just do within one program, and it can all sort of interlock really fluidly. At first, I was really unconfident. I had a couple of scripts where I had some friends who were better at R—people I worked with who would sit down and sort of like help me go through and understand the code. And so it felt like really silly to ask them the kind of like simple question of like, okay, but why is a bracket here, or why would we do this? But they were fortunately really patient people. And then at some point, our entire department said, actually, really everybody needs to be using this because we need everyone on the same platform; we need consistency in our analyses; we need to be able to code review each other's analyses as well. And so we all took an online course together, and that actually helped me feel really a lot more confident because it was walking through each step of what you needed to know, got an opportunity to practice, and you know, then it felt like, okay, you know, even even if there's things I don't know, I've made it through introduction; like I've made it through this next module, so I guess I do know something. And then once I started to apply it in my work, there would still be points where I was like, wait, I don't know; I don't know how to solve this problem. And then I would talk to a friend, uh, you know, Google something, and generally it was like I knew a lot more than than I thought that I did. And from that, I suddenly unlocked my ability to produce a whole lot of analyses quickly with the big data set and also produce a whole lot of data visualizations really quickly using ggplot2.

Hi, my name's Carrie, and I'm a research manager within People Operations at Google.

Hi, great to have you back! Earlier you learned that programming means giving instructions to a computer to perform an action or set of actions. And even if this is your first time programming, you already have plenty of experience telling a computer what to do. For example, you've probably used a spreadsheet function to sort your data or perform calculations, or you might have used SQL to tell a computer how to pull data from a database or join two different data tables. Programming goes even further; it gives you the highest level of control over your data. SQL can communicate with databases, but a general-purpose programming language lets you create your own applications and build your own functions from scratch. To program, you first need to know a programming language. In this video, we'll learn about the basics of programming languages and how they can help you work with your data.

Programming languages are the words and symbols we use to write instructions for computers to follow. You can think of a programming language as a bridge that connects humans and computers and allows them to communicate. Programming languages have their own set of rules for how these words and symbols should be used, called syntax. Syntax shows you how to arrange the words and symbols you enter so they make sense to a computer. Coding is writing instructions to the computer in the syntax of a specific programming language. Just like the variety of human languages around the world, there's lots of different programming languages available to communicate with computers. There's a language for almost anything you want to do, from designing websites to developing video games to working with data. For example, Python is a general-purpose language that can be used for all sorts of things, from working with artificial intelligence to creating virtual reality experiences. JavaScript works well for developing online apps and is an essential part of web browsers. Some other popular programming languages for data analysis include SAS, Scala, and Julia. Personally speaking, R is my favorite language for data analysis, but you might want to explore other languages as well. While programming languages can look different on the surface, they all share similar structures and coding concepts. Once you learn your first language, you'll find it easier to learn others. Coming up, we'll explore R's many capabilities. Before that, let's talk about some benefits of using any programming language to work with your data. I'll highlight three: programming helps you clarify the steps of your analysis, saves time, and lets you easily reproduce and share your work.

Let's start with clarity. Programming languages have specific rules and guidelines for giving instructions to the computer. When you're telling a computer what to do, your instructions have to be very clear. There can't be any inconsistency in the way you write code; if there is, the code won't work. Translating your thoughts into code forces you to figure out exactly how to write each step of your analysis and how all the steps fit together. It gives your analysis a level of precision that makes it really powerful. Using a programming language for data analysis also saves you lots of time. For example, take the process of cleaning and transforming your data. With one line of code, you can create a separate data set without any missing values. With another line, you can apply multiple filters on your data. This lets you spend less time preparing your data and more time on the analysis itself.

Finally, programming languages make it easy to reproduce your analysis. Data analysis is most useful when you can reproduce your work and share it with other people. They can double-check it and help you solve problems. Code automatically stores all of the steps of your analysis so you can reproduce and share your work at any time—in the future, weeks, months, or even years later. Here's an example: let's say you're working on a project. You've collected and cleaned your data and started your analysis, but the results don't add up. You suspect a mistake was made in the process. You'd like to discuss the issue with a teammate and get their feedback. If you used a spreadsheet, you both might have to redo the entire analysis to discover the error. There's no easy way to record and reproduce your steps in a spreadsheet. But if you use a programming language, all your work can be reproduced and shared in a moment—from loading the data to creating visualizations to reporting the results. Plus, you can easily update your analysis and fix any errors simply by changing the code.

I hope that gives you a better understanding of what programming languages are all about. Next up, we'll check out R in more detail. See you soon!

Hello again! Now that we've talked about programming languages in general, let's get to know R. So what is R? R is a programming language frequently used for statistical analysis, visualization, and other data analysis. Later on, you'll take a tour of RStudio, which is a popular software environment for the R language. In this video, we'll discuss R's main features and functions and its advantages for data analysis. R is super cool; I'm excited for you to learn about it.

R is based on another programming language named S. In the 1970s, John Chambers created S for internal use at Bell Labs, a famous scientific research facility. In the 1990s, Ross Ihaka and Robert Gentleman developed R at the University of Auckland, New Zealand. The title R refers to the first names of its two authors and plays on the single-letter title of its predecessor, S. Since then, R has become a preferred programming language of scientists, statisticians, and data analysts around the world. There are lots of reasons why people who work with data love R. I want to share four with you: R is accessible, data-centric, open-source, and has an active community of users.

First, R is an accessible language for beginners. Lots of people without a traditional programming background learn R. I should know; I'm one of them. R really appeals to anyone who wants to solve problems that involve data, and that's one of the things that's so great about R: it's all about data. R is what's known as a data-centric programming language; it's specifically designed to make data analysis easier, more efficient, and more powerful. Another awesome thing about R is that it's open-source. Open-source means that the code's freely available and may be modified and shared by the people who use it. Let's pause for a moment and unpack how amazing this is: first, anyone can use R for free; second, anyone can modify the code, fix bugs, and improve it. In fact, over the years, lots of excellent programmers have made improvements and fixes to the R code. For example, anyone who knows the R language can create what's called an add-on package. We'll talk more about R packages later; for now, just know that literally thousands of R packages exist, and they were all built by people who wanted to solve specific problems. A lot of these packages are super useful for data analysts. As an R user, you now enjoy the benefit of the shared knowledge. And let me just add, the R community is the best! This vibrant, diverse, and accessible community is so supportive of new learners. You can go online anytime to find answers to all your R questions. Check out websites like R for Data Science, the online learning community, and the RStudio community. On top of that, R users are all over Twitter and other social media. You'll discover tons of resources for professional networking, mentoring, and learning.

Now that we know more about the general benefits of R, let's talk about some specific situations when you might use it for data analysis. Here's three scenarios: reproducing your analysis, processing lots of data, and creating data visualizations. First, R can save and reproduce every step of your analysis. Earlier we discussed how data analysis is most useful when you can easily reproduce your work and share it with others.

Others in R reproducing your analysis is as easy as pressing a button on your keyboard. Your code stores it forever, and you can share it with anyone at any time.

Processing lots of data is also something R does really well, just like SQL, as you learned earlier. Spreadsheets organize projects in sheets or tabs; if you've ever had to deal with spreadsheet files that have tons of sheets or lots of data in each sheet, you know that things can start to move very slowly. Working with too much data in a spreadsheet can even cause crashes. R can handle large amounts of data much more quickly and efficiently.

Finally, R can create powerful visuals and has state-of-the-art graphic capabilities, as you've seen in this program. Tools like spreadsheets and Tableau offer lots of options for visualizing your data; R's on another level. With only a small bit of code, you can create histograms, scatter plots, line plots, and so much more—and that's just the beginning. If you work with more advanced packages, you can make some seriously impressive data visualizations.

Learning R's a huge benefit to anyone interested in becoming a data analyst. As I mentioned earlier, knowledge of R will help you stand out as a job candidate, and as you keep moving forward, R will help you find solutions for more complex data problems. You can keep learning about R throughout your career as a data analyst; the sky's the limit when it comes to developing your data analysis skills.

That's all for now. Coming up, we'll check out the RStudio environment together. Before you use RStudio, you need to download and install the basic R interface. You'll learn how to do that in an upcoming reading. Most analysts who work with the R language use the RStudio environment to interact with R and not the basic interface; that's why we're focusing on RStudio in this program. Following this video, you'll find resources for downloading R and RStudio if you're interested in learning more. Bye for now.

Hey there, it's time to take our tour of RStudio. The examples we look at are from RStudio Cloud, but RStudio works in a similar way across all platforms. Feel free to use the platform that works best for you. Later on, if you want to learn more, you'll find resources on how to download and install RStudio on your own device.

RStudio's an IDE, or integrated development environment. This means that RStudio brings together all the tools you might want to use in a single place. The R console, which we explored earlier, is one part of this environment. RStudio also includes an editor for writing code and tools for managing your data and creating visuals. RStudio is built specifically for use with R; it'll help maximize your productivity as a data analyst.

Data analysis is like driving a car. You can think of R and RStudio as different parts of this car. R's like the car engine; RStudio is kind of like the accelerator, the steering wheel, and dashboard all in one. It lets you tell the engine what to do and helps you get to where you want to go. Just as a speedometer and navigation system make driving much easier, RStudio's environment makes using R much easier.

In an earlier reading, you learned how to access RStudio, so let's log into RStudio now and explore. The RStudio environment has four main windows called panes; each pane helps you perform different functions. The first time you open RStudio, you'll see three panes; a fourth pane is hidden by default, but it's easy to open. Just click on File in the menu, then select New File and R Script. RStudio has lots of keyboard shortcuts; to learn more, check out Keyboard Shortcuts help. You can make the panes smaller or larger by clicking on the minimize or maximize buttons at the upper right of each pane. You can also click and drag the borders of the panes to adjust their size. Click on the Panes button for more feature options.

Now that we've got all four panes open, let's explore each of them. We'll start on the lower left and move clockwise from there. You might recognize the R console from an earlier reading. As a quick refresher, the console is the place where you give commands to R. For example, we can tell R to show us a summary of the penguins data that we used in an earlier video to create visuals. You'll need to install and load the palmer penguins data set if you haven't done so already.

Above the console, in the upper left, is the Source Editor pane. You'll use the Source Editor when working with R scripts. There are two main ways of writing code in RStudio: using the console or using the Source Editor. You can type commands directly into the console, but they'll be forgotten when you close your current session. As we've discussed, it's important to be able to reproduce and share all the steps of your analysis. If you save your script in the editor, you can access your work again at any time and show others how you did it.

The Source Editor and the console also work together in RStudio. When you execute code in the editor, the code automatically appears in the console. If you're working on a long analysis, this makes it easy to execute the entire code all at once or run specific sections of it as you go along. Let's run some code in the editor and check it out. Pro tip: Always keep in mind that R is case-sensitive; here we use a capital V for the view function.

Next, let's go to the Environment pane in the upper right. Here you'll find all the data you currently have loaded and can easily organize and save it. For example, if you import data from a spreadsheet, it'll be visible in the Environment pane. You can view each object in the Environment pane by clicking on it. You can also toggle between a list view and a grid view.

To the right of the Environment tab, you'll find the History tab. All your previous commands are saved here, and they're easy to search and re-execute. You'll find the most recent line of code at the bottom of the list. You can copy any line to the command console by double-clicking it.

In the lower right, you'll see a pane that has tabs for Files, Plots, Packages, and Help. The Files tab gives you access to your file directory and shows the contents of the current working folder. You can easily find and manage all your files and create new project folders.

Next is the Plots tab. If we create a plot, the result appears here. For example, we can create a scatter plot with the penguins dataset we used earlier. You'll learn more about creating plots in RStudio later on. Earlier we talked about R packages, which are custom solutions to data problems developed by R users. RStudio gives you access to a library of R packages known as the tidyverse. You can upgrade, install, and manage your library in the Packages pane. Packages loaded in your current session have a check mark. Later on, we'll explore the tidyverse in more detail.

Finally, click on the Help tab. Here you can find helpful resources for R and RStudio. There are tons of resources out there to help answer all your questions; be sure to take advantage of them.

That's our tour of RStudio. We're just scratching the surface of what RStudio can do. Soon you'll get to explore RStudio in more detail. Speaking as a data professional, I love working in RStudio; it makes my work so much easier, faster, and better. Congratulations on finishing another step in your data analyst learning journey. Coming up, we'll learn some basic programming concepts; then we'll start working with R. For those of you who are new to programming, you're about to write your first lines of code. See you then.

Hi and welcome back. We've given you a big picture overview of R and RStudio; now we'll turn our focus to the actual programming and coding you'll do using RStudio. I went pretty far in my career not knowing programming before it became clear I needed to learn it. Getting to know R was such a valuable learning experience. It took some time, and I reached out to more experienced R users with lots of questions, and eventually it all came together for me. Being open to learning new skills is such an important part of your career, and now I'm able to help you learn some new skills too.

I'll start by sharing the fundamentals of programming using R in RStudio. Earlier we explained how R is like the engine of a car and RStudio is like the accelerator, steering wheel, and dashboard all in one. Getting to know fundamentals will help you keep your R car running smoothly. These fundamentals are both alike and different from the other analysis platforms you've come to know well: spreadsheets and SQL. Then we'll move into coding in RStudio. We'll discuss the syntax for performing calculations and the standards and naming conventions for all code. We'll also explore the R tool known as a pipe, which you'll use to make a sequence of code easier to work with and read.

Then we'll check out R packages. While these packages won't be delivered to your door, they are delivered by the R community. These packages contain reusable functions and more and are usually built by users for users like yourself. We'll get to know a collection of packages called the tidyverse. You'll learn how to install the tidyverse so you can start using it in RStudio. We'll also work with some of the more popular tidyverse packages like ggplot2 for visualization. You'll be able to carry over what you've learned about RStudio to the next part of the program where you'll start working with data. As we explained earlier, for this program we'll use the in-browser version of RStudio, RStudio Cloud, but RStudio is also available to be downloaded. So let's get going. See you soon.

Hey there. Anytime you're learning a new skill, from cooking to driving to dancing, you should always start with the fundamentals. Programming with R is no different. To build this foundation, you'll get familiar with the basic concepts of R, including functions, comments, variables, data types, vectors, and pipes. Some of these terms might sound familiar; for example, we've come across functions in spreadsheets and SQL.

As a quick refresher, functions are a body of reusable code used to perform specific tasks. In R, functions begin with function names like print or paste and are usually followed by one or more arguments in parentheses. An argument is information that a function in R needs in order to run. Here's a simple function in action. Feel free to join in and try it yourself in RStudio using your cloud account. Check out the reading for more details on how to get started. You can pause the video anytime you need to. We'll open RStudio Cloud to get started. We'll start our function in the console with the function name print. This function name will return whatever we include in the values in parentheses. We'll type an open parenthesis followed by a quotation mark; both the close parenthesis and end quote automatically pop up because RStudio recognizes the syntax. Now we just have to add the text string. We'll type coding in R, then we'll press Enter. Success! The code returns the words coding in R. If you want to find out more about the print function, or any function, all you have to do is type a question mark, the function name, and a set of parentheses. This returns a page in the Help window, which helps you learn more about the functions you're working with. Keep in mind that functions are case-sensitive, so typing print with a capital P brings back an error message.

Functions are great, but it can be pretty time-consuming to type out lots of values. To save time, we can use variables to represent the values. This lets us call out the values anytime we need to with just the variable. Earlier we learned about variables in SQL. A variable is a representation of a value in R that can be stored for use later during programming. Variables can also be called objects. As a data analyst, you'll find variables are very useful when programming. For example, if you want to filter a data set, just assign a variable to the function you used to filter the data; that way all you have to do is use that variable to filter the data later.

When naming a variable in R, you can use a short phrase. A variable name should start with a letter and can also contain numbers and underscores; so the variable 5_penguin wouldn't work well because it starts with a number. Also, just like functions, variable names are case-sensitive. Using all lowercase letters is good practice whenever possible.

Now, before we get to coding a variable, let's add a comment. Comments are helpful when you want to describe or explain what's going on in your code. Use them as much as possible so that you and everyone can understand the reasoning behind it. Comments shouldn't be treated as code, so we'll put a hashtag in front of it, then we'll add our comment. Here's an example of a variable. Now let's go ahead with our example. It makes sense to use a variable name to connect to what the variable is representing, so we'll type the variable name first_variable. Then, after the variable name, we'll type a less than sign followed by a dash. This is the assignment operator; it assigns the value to the variable. It looks like an arrow, which makes sense since it's pointing from the value to the variable. There are other assignment operators that work too, but it's always good to stick with just one type in your code. Next, we'll add the value that our variable will represent. We'll use the text this is my variable. If we type the variable and hit run, it'll return the value that the variable represents. This is a very basic way of using a variable; you'll learn more ways of using variables in your code soon. For now, let's assign a variable to a different data type: numeric. We'll name this second variable and type our assignment operator; we'll give it the numeric value 12.5. The Environment pane in the upper right part of our workspace now shows both of our variables and their values. There are other data types in R, like logical, date, and date-time. R has a few options for dealing with these data types; we'll explore them later.

With functions, comments, variables, and data types, you've got a good foundation for working with R. We'll revisit these throughout this program and show you how they're used in different ways during analysis. Let's finish up with two more fundamental concepts: vectors and pipes. Simply put, a vector is a group of data elements of the same type stored in a sequence. In R, you can make a vector using the combine function. In R, this function is just the letter c followed by the values you want in your vector inside parentheses. All right, let's create a vector. Imagine this vector is for measurement data that we need to analyze. We'll start our code with the variable vec_1 to assign to the vector, then we'll type c and the open parenthesis, then we'll type our list of numbers separated by commas. We'll then close our parentheses and press Enter. This time, when we type our variable and press Enter, it returns our vector. We can use this vector anywhere in our analysis with only its variable name, vec_1. The values in the vector will automatically be applied to our analysis.

That brings us to the last of our fundamentals: pipes. A pipe is a tool in R for expressing a sequence of multiple operations. A pipe is represented by a percentage sign followed by a greater than sign and another percentage sign. It's used to apply the output of one function into another function. Pipes can make your code easier to read and understand. For example, this pipe filters and sorts the data. Later we'll learn how each part of the pipe works.

So there they are: the super six fundamentals—functions, comments, variables, data types, vectors, and pipes. They all work together as a foundation for using R. It's a lot to take in, so feel free to watch any of these videos again if you need a refresher. When you're ready, there's so much more to know about R and RStudio, so let's get to it.

Hi again. We've shown you how your work as a data analyst can be done in different ways using different tools. That's true in this program, and it'll be just as true when you start your job. Operations and calculations are two concepts we've checked out before; coming up, we'll go back to them and learn how to use operators in R for a range of tasks, including calculations. An operator is one of the key components of a calculation. When we first talked about operators, we defined them as a symbol that names the type of operation or calculation to be performed in a formula. The same is true when we use operators in our code. So let's check out some of these operators in R.

Imagine we've got our hands on some e-commerce sales data that we need to analyze. We'll learn how to use operators to complete calculations on the sales data and for some other tasks too. Throughout our analysis, we'll use variables that are we'll store so that we can reference them whenever we need to. We'll use assignment operators, which we worked with earlier, to do this. Assignment operators are used to assign values to variables and vectors. So if we've got a bunch of sales figures that we want to include in a vector, we can use an assignment operator to assign them to a variable. Here's an example. Now whenever we want to use these sales figures, we just type the variable we assigned.

Next, let's check out arithmetic operators. These operators are used to complete math calculations, and they might seem familiar. Plus signs do addition on variables, and minus signs do subtraction. We use an asterisk to perform multiplication, and a slash performs division. There's other arithmetic operators too, but these are enough to get you started. Let's try a calculation for our sales data in RStudio. Feel free to follow along on your own as we go through these steps. We'll complete our work in a script to make sure our calculations are saved. As an analyst developing code in R, you'll spend most of your time in scripts. When you save a script, you'll have a complete record of your work. You'll use the console mostly to show the results of your programming. Also, even though we're not doing a deep analysis here, it's still a good idea to save our work for easy access later if we need it.

First, let's add a comment. After the hashtag, we'll type our first calculations. We'll start by assigning sales figures from the first two quarters of the year to variables. Before we complete our first calculation, we'll assign it to a new variable, mid_year_sales. Then we'll add our quarterly figures using the plus sign as our addition operator. Let's run it and get the total of our sales data. When we run code in a script, the return shows up in the console. This total is now assigned to the midyear_sales variable. We can check this by typing in mid_year_sales into the console and hitting Enter. You may notice that calculations in R work in a similar way to calculations in spreadsheets and SQL; it's helpful to make connections across the tools that you're working with.

Let's do one more calculation using our total sales from the first two quarters, represented by mid_year_sales. We'll multiply it by 2 to get a general idea of total sales for the year. We'll use an asterisk as our arithmetic operator. You'll find there's other ways to perform these types of calculations, but these are great examples of how the operators work, both for calculations and other operations. For now, let's save our script so that we can use these same variables again if we need to do more work in our sales data. Just like in other formats, we simply click Save As, and then type a file name. The .R file extension is automatically applied to our file name. We'll close our script; when we're ready for more sales data analysis, we can open it again using the File menu. There are other categories of operators that you'll learn about later, but knowing how assignment and arithmetic operators help you program calculations is a good place to start. We're definitely moving forward in R and RStudio; let's keep it rolling by learning more about pipes, another great tool in R. See you soon.

Hello there. I have to say, getting a package delivered to you is one of life's simple pleasures. Doesn't matter if it's a surprise package or something you ordered yourself; it's exciting to open your package to discover what's inside. No wonder those unboxing videos on YouTube are so popular. Well, R has a different kind of package that R users can open. These packages are units of reproducible R code, and they make it easier to keep track of code. They're created by members of the R community to keep track of the R functions that they write and reuse. These community members might then make the packages available to other users; it's one of the great things about being part of this community. Packages in R include reusable R functions and documentation about the functions, including how to use them. They also contain sample datasets and tests for checking your code to make sure it

Does what you want it to do by default. R includes a set of packages called base R that are available to use in RStudio when you start your first programming session. There's also recommended packages that are loaded but not installed. Before using functions from one of these packages, you'd have to load it with a library command, like `library(boot)` for example.

Let's find out which packages we already have in our studio. We'll work in our console instead of a script for now because we're practicing and don't need to save this code for later. To check out our packages, we'll just run the command `installed.packages()`. And there's our list. Let's focus on the Package and Priority columns. The Package column gives the name of the package, like cluster or graphics. The Priority column tells us what's needed to use functions from the package. If you come across the word base in the Priority column, then the package is already installed and loaded. You can use all of the functions of that package as soon as you open RStudio. If you find the word recommended, then the package is installed but not loaded.

You'll also notice a list of packages in the bottom right part of our workspace. This list includes a brief description of each package. To load `class` and other uninstalled packages, we'll need to use the `library()` function followed by the name of the package. And now the `class` package has a check next to it, so it's been successfully loaded for use. If you want to learn even more about your loaded packages, you can click on their names in the Packages tab. This opens the Help tab and shows topics related to the package you selected. You can also use the `help()` function in your programming to call up the Help tab.

While the pre-installed packages give you tons of useful functions, there's even more packages that'll further expand your programming abilities. You can find thousands of R packages just by doing an online search. One of the most commonly used sources of packages is CRAN. CRAN stands for Comprehensive R Archive Network. It's an online archive with R packages, source code, manuals, and documentation. When you start working with R, you'll be able to do your own searches to find packages in CRAN or elsewhere. It's almost always easier to just search with your favorite search engine though. So packages are a pretty big part of using R. They give you most of what you need to complete your programming throughout the data analysis process. Who knows, you might even turn your own code into packages for others to use. Up next, we'll keep unpacking our packages. See you soon.

Welcome back. As we discussed earlier, packages are a big part of what makes R so great. Packages offer a helpful combination of code, reusable R functions, descriptive documentation, tests for checking operability, and sample data sets. And for lots of data analysts, at the top of the list of useful packages is tidyverse. Tidyverse is actually a collection of packages in R with a common design philosophy for data manipulation, exploration, and visualization. Using tidyverse can help you work your way through pretty much the entire data analysis process. The packages in tidyverse work together naturally. I started learning about tidyverse when I was working on a survey project. It felt like I was stepping into a more advanced zone of R. I understood the basics, but now I was finding out how the tidyverse improves on the basics. That's when I got even more excited about working in R. I realized that the more I put into learning about the tidyverse, the more I'd get out of it. On top of that, the community support for tidyverse is strong too. It's one of the reasons why tidyverse is considered a key part of programming for most R users. The principles associated with tidyverse, which you'll learn both here and at your job, have been widely adopted by the R community. You'll find lots of tutorials and examples related to the tidyverse online that show you these principles and how they're applied to data analytics.

Okay, let's install the tidyverse. You can follow along on your own using your RStudio Cloud account. Check out the reading for more details. Earlier you learned how to find base R packages using the function `installed.packages()`. To install packages like the tidyverse that aren't in base R, we'll use the `install.packages()` function. As we discussed earlier, this function calls the tidyverse and other packages from CRAN. Let's talk about why CRAN was created. Since packages not in base R are mostly made by R users, people need a reliable way to check and validate submitted code. CRAN makes sure any R content open to the public meets the required quality standards. So if it's sourced through CRAN, you can feel good that the package is authentic and valid. Another major source of packages and other R content is GitHub. Now we'll get back to installing the tidyverse. We'll first type `install.packages()`, then between the parentheses we'll type `"tidyverse"`. The quotes aren't always necessary, but best practice is to use quotes to make sure that we're accurate. We'll press Enter and wait for RStudio to install tidyverse. When we click on our Packages tab, we come across a lot of new packages on the list—that's tidyverse. You might have noticed that none of the packages are checked off. We need to load them first before we can use them, but that's a mighty long list. So let's just load the package named tidyverse for now using the `library()` function. The return shows that not only was tidyverse loaded, but eight other packages were too. It also shows a list of conflicts. Conflicts happen when packages have functions with the same names as other functions. Basically, the last package loaded is the one whose functions will be used. So we'll stick with the tidyverse functions, but it's important to note that these messages only appear once. So as you get more used to R, you'll be able to figure out if you want to use certain functions over others. The loaded packages are ggplot2, tibble, tidyr, readr, dplyr, stringr, and forcats. These packages are the core of the tidyverse because you'll use them in almost every analysis. All of them work together to make your data analysis smooth and efficient. With these packages, tidyverse helps you do everything from importing and transforming data to exploring and visualizing it. We'll check out this core of packages soon and we'll use them even more as we continue working in our studio. If you're working on your own and are you can check out some of the other packages too. The packages available in tidyverse change a lot, but you can always check for updates by running `tidyverse_update()` in your console. You can then update the packages in a couple of ways. If you use the `update.packages()` function, it'll update all of your packages—that might take a while. So if you just want to update one package, you can use the `install.packages()` function again with the package name as your argument in parentheses. You should update packages regularly to make sure you've got the latest version in your code. Conflict notifications are just one type of message that can show up in the console. You might find warnings and error messages as well. A quick search using the Help tab will usually tell you what the message means and what, if anything, you'll need to do to address it. Coming up, we'll keep moving through the tidyverse. You'll find out more about why tidyverse is such an integral part of R. See ya.

Great, you're back. Have you ever taken a tour of a famous landmark or an unfamiliar city? It can be pretty exciting. You get to learn all about the features of the landmark or city. Eventually, you get to know them pretty well, and you can share what you learned with others. Well, we're here to take a different kind of tour—a tour of the tidyverse. For this tour, we won't be traveling anywhere special, but we will help you learn about the exciting tidyverse features. And once you know them a little better, you can most definitely share what you learned with others. For this tour, we'll focus on the core packages of tidyverse we discussed earlier: ggplot2, tidyr, readr, dplyr, tibble, stringr, and forcats. We also learned how to install and load them in RStudio. Once they're loaded, you won't need to do anything else with their actual packages; they'll do their thing as you program. So what is their thing? Well, it depends, but there's four packages that are an essential part of the workflow for data analysts: ggplot2, dplyr, tidyr, and readr. You'll most likely use these more often than the others. ggplot2 is used for data visualization, specifically plots. With ggplot2, you can create a variety of dataviz by applying different visual properties to the data variables. Here's an example of ggplot2 in action. You'll have your own chance to use ggplot2 later. tidyr is a package used for data cleaning to make tidy data. We covered tidy or clean data earlier, but as a quick reminder, it's data where every part of a data table or data frame is the right type in the right place. tidyr works with wide and long data to make sure this happens. Next, we have readr, which is used for importing data. The most common function from readr is `read_csv()`. This will import a CSV file into R. A CSV file contains data separated by commas in a table format. To accurately read a data set with readr, you combine the function with a column specification. The column specification describes how each column should be converted to the most appropriate data type. It's good to keep in mind this isn't usually necessary because readr will figure it out for you automatically. We'll come across readr functions as we continue to explore R. Now on to dplyr. dplyr offers a consistent set of functions that help you complete some common data manipulation tasks. For example, the `select()` function picks variables based on their names, and the `filter()` function finds cases where certain conditions are true. And yes, dplyr is another package we'll get to later. There's plenty to look forward to. So that's the fab four of the tidyverse. They'll all make your programming in R more straightforward and efficient. The other four packages are definitely useful too, but you might not use them as often. tibble works with data frames. purrr works with functions and vectors, helping make your code easier to write and more expressive. stringr includes functions that make it easier to work with strings. forcats provides tools that solve common problems with factors. As a quick reminder, factors store categorical data in R, where the data values are limited and usually based on a finite group like country or year. Using the tidyverse and its packages will help you fine-tune your analysis. Besides tidyverse, you also learned the fundamentals of R, from variables to vectors and more. You explored the different operators in R and saw how they can help you complete calculations. You had the chance to check out pipes and how they can make your programming more efficient, and you unpacked packages to find out how they're a big part of what you can do in R. We've covered a lot of ground in just a few videos, so this might be a good time for you to do a little review. You can re-watch videos and revisit any other resources that can help you get an even better grasp of all the terms, concepts, and processes that are part of R. Looking ahead, you'll start working with data in R, including a more thorough exploration of how tidyverse impacts your process. You'll see tibble, readr, and other tidyverse packages in action, and you'll find out how to clean and organize your data in R. All this and more coming up. I'll see you soon.

Hi again. Earlier we introduced something called pipes. A pipe is a tool in R that helps make your code more efficient and easier to read and understand. In this video, we'll explore pipes in more detail. As a quick reminder, a pipe is a tool in R for expressing a sequence of multiple operations. In other words, it takes the output of one statement and makes it the input of the next statement. So instead of typing out functions contained inside other functions, you can use the pipe operator to do the same work in programming. We describe this as nested—describes code that performs a particular function and is contained within code that performs a broader function. You can think of a pipe as a way to code the phrase "and then." Say you've got sales data and you need to find the mean or average. You can create a pipe by calling up the data and then grouping the data and then summarizing the group data using a mean function. Let's check out an example. First, we'll open RStudio, then we'll start a new script so we can save our work. We'll save it as `tooth_growth_exploration`. We'll use the `toothgrowth` data set, which is already installed in R. This data set contains data about the effect of Vitamin C on the growth of teeth in guinea pigs. It's a well-known data set that will help us learn about how pipes work. To load any data set already installed, we use the `data()` function. We then add the name of the data set, `toothgrowth`. Now that the data is loaded, we can check it out with the `View()` function. Notice how `View()` begins with a capital V. It's a good reminder that functions and variables are case-sensitive in R. In a script, we use the Run button to run our code. The return usually shows up in the console, but with `View()`, a new tab appears in the script showing the contents of the data set. Now let's say we need to filter and sort this data to organize it for analysis. Without pipes, we could do this either by nesting commands or by creating a sequence of data frames. We'll chat more about data frames soon. Let's start by filtering the data set. Note that we'll want to first install and load the correct `filter()` function, which comes as part of a package. Installing a package may take a few moments. This function comes as part of the dplyr package. We'll assign a name to the new data set and then apply the `filter()` function. This filters the data so that we only see rows where the dose of Vitamin C is exactly 0.5. This includes both types of Vitamin C used in the study: orange juice (OJ) in our data set and ascorbic acid (VC). Next, we'll sort it with the `arrange()` function. We'll include the name of the filtered data set followed by the column name we want to sort by—in this case, `len`, which stands for length of tooth. When we run this, the return appears in the console. The data is arranged in ascending order by `len`. The return only shows rows where the dose amount is 0.5, so the data's been filtered and sorted based on our code. Let's try another way to get the same return. We'll use a nested function, which is a function that is completely contained within another function. Here's the nested function for filtering and sorting this data set. Notice that the `filter()` function from our previous code is the nested function. With nested functions, we read from the inside out. The code filters the data first, then it arranges or sorts it. Now let's run this. We tweaked the code, but we get the same result. Now we'll use a pipe. As a quick reminder, the operator used to call out a pipe is a percentage sign followed by a greater-than sign and another percentage sign (`%>%`). You can also use keyboard shortcuts to insert pipe operators: Ctrl+Shift+M for PCs and Chromebooks, and Cmd+Shift+M for Macs. We'll start this pipe by assigning it to a variable, then we'll type the name of the data set we're pulling data from, `toothgrowth`. We'll use our keyboard shortcut to add the pipe operator after that. Now we can press Enter to go to the next line. RStudio automatically indents the next line, recognizing that it's part of the pipe. Next, we'll filter the data. We don't have to call out the data set inside parentheses like we did in earlier examples because we started our pipe with it. The pipe automatically applies the data set to each step. Alright, let's finish up our pipe on a new line with the `arrange()` function and sort the data. Since this is our last line of code, we don't need a pipe operator. Finally, click Run, and presto, we get the same return as our other methods. Our pipe is set up to call the data set and then filter the data set and then sort the data set. All three methods work, but you can see how pipes help make your programming more efficient and less cluttered. This means fewer chances for mistakes and better readability for anyone looking at your code. And because of the structure of a pipe, we can easily add to or change the code without having to start over. So let's do that. Building on our example, let's say we also wanted to compute the average tooth length (`len`) for each of the two supplements used in the study: orange juice (OJ) and ascorbic acid (VC). We'll replace the `arrange()` function with the `group_by()` function. This will group our results by the two supplements. So we type `supp` in the parentheses and add a pipe. We're adding a pipe this time because we have another line of code to add. So we group by, and then we summarize. Our argument, which comes after the function `summarize()`, looks pretty complex, but it basically tells R what to do with missing values and to make sure the data is grouped the right way. When we add the `summarize()` function, now we'll run our new pipe and get the average length of tooth when the dose is equal to 0.5 for each of our supplements. Nice. Now there's a couple of things to remember when using pipes. First, it's important to add the pipe operator at the end of each line of the piped operation except the last one. Another group rule of thumb is to check your code after you've programmed your pipe. Remember, RStudio automatically indents lines of code that are part of a pipe. If a line in your code isn't indented, it probably hasn't been added to the pipe; that could lead to an error statement. Then you can revisit the piped operation to check for parts of your code to fix. With the other methods we showed you, it'd be more of a challenge to find the messy parts—another reason to use pipes when you can. Pipes, or piping, and the functions that are part of the piping process are building blocks for putting together analyses in R. In upcoming videos, you'll learn how you can use these building blocks to clean, transform, and analyze your data. For now, feel free to take your time reviewing and maybe even practicing with the functions, operations, and other elements in R and RStudio that we've already covered.

Hi, I'm Connor, and I'm a marketing analytics manager at Google Cloud. I was running into barriers of not being able to do certain analyses because it was too time-consuming with my limited technical knowledge. So I started to teach myself things like SQL to help me access data through the current company's database that I had so that I could manipulate that data to better understand it. I can tell you, at first, it is an incredibly frustrating thing to move through because it takes a lot of time and effort to do something that seems very simple, or something that would be very easy to do in spreadsheets, but may be very difficult to do at first as you're learning how to code. But also, one of the most fulfilling things that I've ever done because once you're able to understand something, it opens up an entire new realm. Learning coding was revolutionary for my job. I remember when I first started as an analyst, all of the data that I used was in spreadsheets, and I had to run analyses and create formulas to manipulate the data, understand the data, and even analyze the data. Now, when we started to get more and more data, the formulas that I would run would take hours. And I remember at one point I had—I spent a few hours creating a formula and then executed it, and it took over 10 hours to run. So I left my computer open and let it run throughout the night, woke up, and it was still running. Fast forward a year later, after I had learned SQL and Python, I was able to run the same type of analysis in milliseconds. So really understanding what it is that you are trying to do, coding helps you manipulate and uh analyze data at a rate that previously—or without a coding knowledge—would be very difficult to do. An important aspect of any type of script or when you are coding is to structure it for overall readability. More often than not, you're going to be working on a team. Now it's important that when you're writing a script that you understand how it works, but also that somebody else who you work with can also come and understand what it is that you are trying to do within that script. Now it's

Very important that it not only works and is efficient, but that it is also not too verbose; meaning that it is not overly complex. So an important aspect of readability is: if you are looking through your code and you realize that I've written the same thing multiple times, or I'm using the same logic or algorithm multiple times, that is a point in time where you can really consolidate your code and make it a lot more concise, which vastly helps with readability. It vastly helps anybody who comes and is trying to read your code, and that includes you two weeks from now. Because I can promise you, when you start coding, you will realize that what makes sense to you right now may not make sense to you three weeks from now.

An important aspect for readability and overall understanding of your code is using comments. Comments are a way to write something out in a standardized language like English, a way that somebody can understand it, but the computer doesn't pick up as actual code. So, for explaining every line that you write, or explaining an entire section of your code in a comment, allow somebody to walk themselves through your code and read exactly what it is that you are trying to accomplish with the code that you've written. Now, without comments, you are leaving it up to the person to really follow your code and understand it themselves, which may not be an easy task for somebody because they may have a different way of coding the same thing that you are doing.

Documenting your work is an important aspect. Documentation will explain in depth exactly what your code is doing, why it was built, what is the purpose for it, and any limitations. The last one is a rather difficult concept to understand as you are first diving into learning a coding language, and that is building it for scalability as well as making it dynamic. Now, when I say building something for scalability, what I mean is: if you are building a specific script of code to solve a task that you're running now, what you want to be sure is—and answer is—will this code, or could this code be used in the future for something else? Now, if it is, it's important that you make your code available to be scalable. That means that it is efficiently run so that if the size of the data that it is running any manipulations on increases, it doesn't bog down your code too much, and that it can handle large data loads as well as small. Another aspect to that is making your code dynamic. So what that means is not hard coding any values within your code that don't change when they need to.

These are just a few of the best practices, and as you continue down your path as a data analyst, you'll pick up many, many more. There's always more to learn, there's always more to understand, but this should help you in beginning down your path to understanding coding. Hey, it's great to have you back. Now that we've been introduced to R and programmed with it, let's learn about even more ways you can use R during our analysis process. We'll start by learning more about data frames and how to use them, and then explore how to work with our data in different ways using tidyverse packages. After that, we'll cover how to check for bias in R. R's community has really helped me grow as a data analyst, especially when it comes to processes like data cleaning. R helps me clean more efficiently, and I can turn to a community of folks to learn how they have cleaned similar data. Sharing knowledge of R and being able to code review has improved my work a ton. I'm so excited to show you new ways to work with R and get more out of your data. Earlier I mentioned that learning R was going to be fun; here's where we get to take what we've learned so far and put it into action. When you're ready, you can get started in the next video. See you soon.

Hey, welcome back. Before we can start cleaning and organizing our data, or even check it for bias, we need to get our data into a usable format. This is where data frames come in. You might remember we talked a little bit about data frames before. In this video, we'll learn more about what data frames are and how you can use them. Let's get started. First, let's talk about what a data frame is. A data frame is a collection of columns; it's a lot like a spreadsheet or a SQL table. Here's an example of a data frame in R; it's a lot like other tables we've worked with throughout this program. There's column names and rows and cells with data. The columns contain one variable, and the rows have a set of values that match each column. We use data frames for a lot of the same reasons as tables too; they help summarize data and put it into a format that's easy to read and use. There's some things to know about data frames before working with them. We'll learn more about data frames throughout this program, but this is a great starting point. First, columns should be named; using empty column names can create problems with your results later on. Let's think back to our example; each of the columns are named based on the variable they represent: carat, cut, color, clarity, depth. All of these columns represent data about the diamonds. Next, it's important to know that the data stored in your data frame can be many different types, like numeric, factor, or character. Often data frames contain dates, timestamps, and logical vectors. Finally, each column should contain the same number of data items, even if some of those data items are missing.

Data frames are foundational. Now let's talk about tibbles in the tidyverse. Tibbles are like streamlined data frames; they make working with data easier, but they're a little different from standard data frames. First, tibbles never change the data types of the inputs; they won't change your strings to factors or anything else. You can make more changes to base data frames, but tibbles are easier to use. This saves time because you won't have to do as much cleaning or changing data types in tibbles. Tibbles also never change the names of your variables, and they never create row names. Finally, tibbles make printing in R easier; they won't accidentally overload your console because they're automatically set to pull up only the first 10 rows and as many columns as fit on screen—super useful when you're working with large sets of data. Data frames and tibbles are the building blocks for analysis in R, so having set standards for how they're built and dealt with is pretty important. If we all have the same understanding of what a data frame is, we can communicate more effectively; it's like we're all speaking the same language. It's also just a lot more practical; we need to be able to do things like define columns and review code easily in R. These characteristics make it easier to share your data and reproduce your analysis. Consistent data structures like data frames make it easier to operate on an entire data set. Tidy data refers to the principles that make data structures meaningful and easy to understand; it's a way of standardizing the organization of data within R. These standards are pretty straightforward: variables are organized into columns, observations are organized into rows, and each value must have its own cell. Now that you know a little more about data frames, let's start using them. Coming up, I'll teach you how to create data frames, add data to them, and expand them. Bye for now.

Hey there. Earlier we learned about data frames and their key characteristics; now we'll actually start working with them. As a data analyst, a lot of your work will depend on data frames; if you don't create a data frame, your ability to work with your data will be limited. Think about spreadsheets; that basic structure of columns and rows carries over to R. Data frames are basically the data analyst's default way to interact with data; that's why knowing how to create and work with data frames is so important. So let's check out an example here. We'll use R's built-in data frames. One of the great things about R and R packages is that there's a lot of interesting, easy to access data sets built in. These data sets let you practice some of the tools we've been learning. Let's open our studio and get started. We'll use a pre-loaded data set with information about diamonds. This data set's part of the ggplot2 package in the tidyverse, so make sure you first load ggplot2. We'll learn how to load our own datasets later too, but diamonds is a good dataset to practice with. We can load this data now by using `data()` open and close parentheses. You might notice that when we start to type diamonds, our studio gives us the option to select it from its drop-down menu; that's because this data set already exists in our library. Okay, now let's add this data frame to our data viewer. There's 10 columns and 100 rows in this data frame, but we might not want to see all of it. We can use the `head()` function to give us just the first six rows. This is a nice preview of the entire data set. Accidentally printing the full data frame to the console can be annoying and can take a long time to compute; you can avoid printing the full data frame by using functions like `head()` to get a quick preview. We can also get the structure of the data frame using functions like `str()` and `colnames()`. These are just two functions you can use to check out your data. We'll explore other functions like `glimpse()` later on. For example, we could use the `str()` function to highlight the structure of this data frame. This gives us some high-level info like the column names and the type of data contained in those columns, but if we just want to know the column names, we can use `colnames()` instead. Here we have carat, cut, color, clarity, depth—all of the columns included in this data set. We can also use the `mutate()` function to make changes to our data frame. The `mutate()` function is part of the `dplyr` package, which is in the tidyverse, so you'll need to load the tidyverse library before you test out `mutate()`. Let's add a new column first. All we have to do is input `mutate()`, and then tell R we want to add a new column to the diamonds data frame. We'll first call `mutate()`, followed by the name of the data frame we want to change, then we'll add a column and the name of the new column we want to create, then we want to calculate this new column. In this case, to make it easier to read the carat column, we'll multiply it by 100 to create a new column `carat_two`, and when we run this, presto, our data frame has a new column. You won't lose any columns when you create the new one; the rest of the data frame will still be the same. Data frames are usually the starting point for analyzing data in R, so it's important to understand the characteristics of data frames and how to create them. Great job, and I'll see you next time.

Hi again. Now that we've got a little more experience with data frames, we can start doing some interesting things like clean, standardize, manipulate, and visualize data. We'll go through some common tasks that you'll perform as a data analyst, but we're just scratching the surface of what you might want to do in R. We'll start with the basics and learn how to clean up our columns. There will be a reading with a handy list you can refer to afterwards too. Let's install the `here`, `skimr`, and `janitor` packages. Now we'll go ahead and open our console. First, we'll add the `here` package. This package makes referencing files easier; to install it, we'll just write `install.packages()`, and then in the parentheses we'll put `here`, and RStudio will install it. After we install it, we'll also need to load it using `library()`. Next, we'll install `skimr` and `janitor`. As a quick reminder, these packages simplify data cleaning tasks; they're both really useful and do slightly different things. The `skimr` package makes summarizing data really easy and lets you skim through it more quickly. We'll install it now. The `janitor` package has functions for cleaning data after it's done installing; we'll still need to load it. Finally, we want to make sure the `dplyr` package is loaded since we're going to be using some of its features there. Now we've got all the packages we need for basic data cleaning. Now let's load some data in. Later when you're practicing with your own data, you can use `readr` to grab a file; for example, if you had a CSV you wanted to load, you could write `read_csv()`, and input the file name in the parentheses. This is where the `here` package comes in handy, so be sure to install and load the `here` package before trying to save CSV files. For now, we'll load a really fun package to practice with: the `palmerpenguins` package. This is a data set we've used before, but just as a quick reminder, the `palmerpenguins` data has lots of information about three penguin species in the Palmer Archipelago, including size measurements, clutch sizes, and blood isotope ratios—and who doesn't love penguins? First, we'll install the package, so we'll type `install.packages()`, and input `palmerpenguins`, and then remember to load it by using the `library()` function. And now that we've got this data loaded into our library, we can try some cleaning functions on our columns. There's a few different functions that we can use to get summaries of our data frame: `skim_without_charts()`, `glimpse()`, `head()`, and `select()`. The `skim_without_charts()` function gives us a pretty comprehensive summary of a data set; let's try it out. When we run this, we get a lot of info back; first it gives us a summary with the name of the data set and the number of rows and columns; it also gives us the column types and a summary of the different data types contained in the data frame. Or we could use `glimpse()` to get a really quick idea of what's in this data set. When we run this command, it'll show us a summary of the data; there's 344 rows and eight columns. We have species, island, measurements for bills (which are basically beaks) and flippers, the penguin's body mass in grams, the sex, and finally the year the data was recorded. We can also use `head()` to get a preview of the column names and the first few rows of this data set. Having the column names summarized like this will make it easier to clean them up. We can use `select()` to specify certain columns or to exclude columns we don't need right now. Let's say we only need to check the species column; we can input `penguins`, then a pipe to indicate we'll add another command, and our `select()`. We'll jump back into an R script because it will be easier to see. Now we have just the species column. Or maybe we want everything except the species column; we'll put `-species` instead of `species`, and now we have every column but species. The `select()` statement is useful for pulling just a subset of variables from a large data set; this lets you focus on specific groups of variables. There's a lot of other `select()` functions that build on this that we'll cover later on. Now that we know our column names, we've got a better idea of what we might want to change. The `rename()` function makes it easy to change column names. Starting with the `penguins` data, we'll type `rename()`, and change the name of our island column to `island_new`. Now looking at our column names, we can see the column name has changed. Or let's say we want to change our columns so that they're spelled and formatted correctly in spreadsheet programs. As long as our column names are meaningful, they're fine, but since we have to type the column names over and over in R, we need them to be consistent. Similar to the `rename()` function, the `rename_with()` function can change column names to be more consistent. For example, maybe we want all of our column names to be uppercase; we can use the `rename_with()` function to do that. This will automatically make our column names uppercase, but since variable names are usually lowercase, we'll use the `tolower` option to change it back. The `clean_names()` function in the `janitor` package will automatically make sure that the column names are unique and consistent. Let's try the `clean_names()` function on our penguins data. This ensures that there's only characters, numbers, and underscores in the names, and now you know some functions for cleaning columns in your data sets. Try practicing them on your own with the `palmerpenguins` data, and once you're comfortable with these functions, we'll learn even more about data cleaning in R. See you soon.

Hey, great to have you back. We've learned how to create data frames and perform some basic cleaning functions; now it's time to start getting organized in R. Coming up, I'll teach you some functions that'll help you organize and filter your data. These functions look a little different in R than in other tools we've used so far, but the reason we use them is still the same: if we don't organize our data, we can't turn information into knowledge. Organizing our data and comparing different metrics from that data helps us find new insights; in other words, it makes our data useful. To help us do this, we'll use the `arrange()`, `group_by()`, and `filter()` functions. Let's start by sorting our data. Let's keep working with the `palmerpenguins` data from earlier; in case you don't remember, refer to the link below. We'll also need to load the right packages. We can use the `arrange()` function to choose which variable we want to sort by. For example, let's say we want to sort our penguin data by bill length; we'll type in `arrange()`, and our column name, and when we execute this command, it'll return a table with data sorted by bill lengths. It's currently in ascending order; if we want to sort it in descending order, we just add a minus sign before the column name, and now the longest penguin bill is first. Now it's important to remember this data is just in our console; to save this as a data frame, we'll start by naming it, then we'll input the function we used to arrange the previous version of the penguins data. When we execute this, it'll save a new data frame, and we can use `view(penguins2)` to add it to our data viewer. This lets you save cleaned data without losing information from the original data set. You can also sort data by using the `group_by()` function. `group_by()` is usually combined with other functions; for example, we might want to group by a certain column and then perform an operation on those groups. With our penguin data, we can group by island and then use the `summarize()` function to get the mean bill length. We checked out the `summarize()` function when we introduced piping; basically, the `summarize()` function lets us get high-level information about our penguin data. So let's build our `group_by()` statement first. We're not interested in NA values, so we can leave those out using the `drop_na` argument. This addresses any missing values in our data set; it's important to be careful when using `drop_na`; it's useful when doing a group-level summary statistic like this, but it'll remove rows from the data. Now let's use `summarize()`; we'll title the summary column `mean_bill_length_millimeters`, and then we'll build the mean statement, and when we run this, we get a data frame with the three islands and the mean bill length of the penguins living there. We can get other summaries too; for example, if we want to know the maximum bill length, we can write a similar function and replace `mean` with `max`, and now we know that the penguin with the longest bill lived on Biscoe Island. Both `group_by()` and `summarize()` can perform multiple tasks; for example, we could group by island and species and then summarize to calculate both the mean and max. To do that, we can write a similar command; we'll put species and island in our `group_by()`, and drop any missing values, and then we can add a `summarize()` statement with a max and mean calculation, and when we run this, we have both groupings and the max and mean. Thanks to piping, we can combine all of these cleaning and transforming tasks into one code chunk. Finally, we can filter results using the `filter()` function. Let's say we only want data from Adelie penguins; we'll start with the data set we're using, and then add the `filter()`. You might notice that we're using two equal signs here; that's on purpose. The double equal signs mean exactly equal to in R, and now we have a data frame that only contains data from Adelie penguins. This lets us narrow down our analysis if we need to. Being able to clean and organize data is a key step in the data analysis process, and knowing the right tool for the job is an important skill for a data analyst. R makes wrangling data easier and gives you a lot of functionality across different stages of the data analysis process. Now that we've cleaned our data, we can get ready.

To transform it, coming up we'll learn about the separate, unite, and mutate functions and how to use them to transform our data in R. See you next time.

Welcome back. So far, we've started cleaning and now working with data in R. Now let's talk about how to transform data. Sometimes you need to be able to break up a variable across multiple columns, or combine existing columns, or even add new values to your data frame. Coming up, we'll use the separate, unite, and mutate functions to transform our data in R. Luckily, the packages already downloaded into our library have some tools we can use to do just that. Let's open RStudio Cloud and check them out.

To start, we'll create a data frame from scratch for this example. We'll create a standard data frame so that we can test out other functions, but you could also make a tibble. Since we're manually inputting the data, you'll learn more about tibbles in a reading. For our data set, we're going to copy and paste some data to create our own data frame. If you want to use the same data to follow along, check out the earlier reading. Our data contains employee information, including names and job titles. You can just copy it in. We can then name the data frame "employee," indicate the column names as "id," "name," and "job title," and print the whole data frame. Right now, the first and last names are combined into one column. We can use the separate function to split these into separate columns.

We'll start with `separate`, and then the data frame we want to work with, and the column we'd like to separate. Then we'll add what we'd like to split the name column into. We'll just name these new columns "first name" and "last name," and finally, we'll tell R to separate the name column at the first blank space. When we run this, it'll build us new columns for the first and last names. The `separate` function has a partner, `unite`. The `unite` function allows us to merge columns together; basically, it does the opposite of `separate`. Let's say we're working with the version of this data frame with two name columns, and we want to combine them. We'll copy in this data as well. Our `unite` statement's a lot like our `separate`. We'll start with `unite` and indicate the data frame we're referring to. Then we'll name the column we're combining "first name" and "last name" in, and then we'll say which columns we're combining (no quotation marks needed here), and finally we can include a space that separates them. When we run that, those two columns are combined.

In addition to separating and merging columns, we can also create new variables in our data frame using the `mutate` function. We worked with `mutate` a little bit before to clean and organize our data, but `mutate` can also be used to add columns with calculations. Let's go back to our penguin dataset. Right now, the body mass column's measured in grams; maybe we want to add a column with kilograms. To do that, we'll use `mutate` to perform the conversion and add a new column, and it'll return a tibble with our new column. You can make calculations on multiple new variables by adding a comma. Let's add a column converting the flipper length too. Now we've learned how to transform existing data in our tables and how to create new variables. `separate`, `unite`, and `mutate` are some basic functions that we'll keep building on, and you might discover new ways to use them while you're practicing too. Coming up, we'll talk more about summarizing data frames and how to address bias. I'll see you soon.

Great to have you back. Earlier we talked about summarizing data in R, and we even used the `summarize` function to calculate the mean for one of our penguin data variables. Now we'll work with a very famous data example: Anscombe's quartet. Anscombe's quartet has four data sets that have nearly identical summary statistics, but those summary statistics might be misleading. Data visualizations, especially for data sets like these, are so important. They help us discover things in our data that would otherwise remain hidden. Plus, you'll discover some of the ways R can create awesome visualizations. Let's install the packages; this may take a few minutes to load. Okay, let's load the Anscombe's quartet data. Now when we view this data, we notice that there's four sets of x and y axes in the data frame; that's the quartet. Data can be summarized by different statistical measures. We'll get a summary of each set with the mean, standard deviation, and correlation for each of these data sets. We'll start by indicating that we want to group our data by set, then we'll input our `summarize` function. When we run this, we'll get a summary of these statistical measures in our summary tibble. We can check the mean; the mean for x in each data set is 9, and the mean for y is 7.5. Standard deviation can help us understand the range of values in a data set, and the standard deviation for x and y in every set in the quartet is the same: 3.32 and 2.03. Finally, we've got our correlation, which shows us how strong the relationship between two variables is. Here it looks like the correlation between x and y in all four sets is around 0.816. So, based on the summaries we created with our statistical measures, these data sets are identical. But sometimes just looking at the summarized data can be misleading. Let's put together some simple graphs to help us visualize this data and check if the data sets are actually identical. You'll learn more about plotting data in R later, but for now we'll just get a quick idea of how this data appears. Check it out; these four data sets appear quite different when we visualize them. If we just gone with a statistical summaries, we never would have known that this data is actually really different. I want to show you one more really cool thing: the `datasauRus` package. The `datasauRus` creates plots with the Anscombe data in different shapes, but let's run it to see that for ourselves first. You'll start off with installing and loading the package, then we'll create a chart. It's okay if these commands seem complicated; you'll be creating your own plot soon. This is just a sneak peek at how R can help you create data visualizations. When we run this, it shows us several different plots; there's the famous dinosaur, a bullseye, a star. R is a pretty powerful visualization tool; you could use the relationships between data points to create many other shapes. As you can see, you can do a lot of things with R. Data visualizations like the ones we just explored help you discover so much more about the data you're working with. It's important to explore your data in multiple ways to learn a little bit more about its story. Next we'll learn how to use R functions to check for bias.

Hey, welcome back. By now you've already learned the importance of fair, unbiased data in data analysis. In R, we can actually quantify bias by comparing the actual outcome of our data with the predicted outcome. There's a pretty complicated statistical explanation behind this, but with the `bias` function in R, we don't have to perform this calculation by hand. Basically, the `bias` function finds the average amount that the actual outcome is greater than the predicted outcome. It's included in the `simdesign` package, so it's helpful to install that and practice on your own. If the model is unbiased, the outcome should be pretty close to zero. A high result means that your data might be biased, a good thing to know before you analyze it. Let's say we're working with a local weather channel to determine if their weather predictions are biased. First, we'll need to install and load a package called `simdesign`. We'll use the `bias` function to compare forecasted temperatures with actual temperatures. For this example, we'll just take a small sample of our weather data and input them here. We'll label this the "actual temp," then we'll put in the predictions, and then the `bias` function. When we run this, we can find out that the results 0.71; that's pretty high. The predictions seem biased towards lower temperatures, which means they aren't as accurate as they could be. And now that the local weather channel knows, they can find the problem in their system that's causing the biased predictions. This doesn't mean their predictions will be perfect all the time, but they'll be more accurate overall. And that's it for now. We've covered a lot here. We learned about how to create data frames; we got to try out some basic data cleaning functions; we got a little preview of how dataviz in R can help us better understand our data; and finally, we learned how to use the `bias` function. I've still got a lot more I want to tell you about R, and if the data visualizations we created in this module were exciting for you, I've got great news. Coming up, we'll learn all about data visualization in R, but first you've got a weekly challenge to tackle. I know you're going to do great, and if you want to review any of the material that we've covered in these videos, feel free. This might be the first time you've encountered R, so it's a great opportunity to practice something new. Your code might throw up some errors at first; that's just part of writing code. It's okay to try things out and make some mistakes. Learning from our mistakes is how we grow. I'll see you afterwards for our next adventure in R.

Hi there. Great to see you again. I've really enjoyed introducing you to R. By now you know your way around R and RStudio, and you're familiar with some basic programming concepts. You've also learned how to clean and organize data in R. You've taken on the challenge of learning programming and developed new skills for data analysis. Great job. Now you'll learn how to use code to visualize your data. Data visualization is one of the most important parts of data analysis. Powerful visuals show stakeholders what your data means in a clear and compelling way, and highlighting key insights. Visuals help bring the story of your data to life and make that story easier to understand. You might remember the sneak peek I gave you of R's data visualization powers. I created those visuals with `ggplot2`, one of the core packages of the tidyverse. `ggplot2` is R's most popular visualization package, and for good reason; it's a powerful and user-friendly data vis tool. Up next, you'll learn how to write and execute all the code we previewed earlier. You'll learn how to use `ggplot2` to create a variety of plots, organize and represent different variables in your data set, and customize the look and feel of your visuals. Working with `ggplot2` can help you get the most out of your data. Your new dataviz skills will also make it easier to learn other parts of R going forward. You'll be better able to visualize the results of any change you make to your data, plus you get an immediate result for all your hard work, which is one of my favorite parts of creating plots in `ggplot2`. Just enter some code, run it, and out comes a cool-looking visual that helps you and others understand your data. Visualization is a key part of a data analyst's workflow, and R lets you move back and forth between analysis and visualization quickly and easily. I'm looking forward to showing you what `ggplot2` can do. See you soon.

Hi again. In this video, we'll focus on `ggplot2`. We'll learn about its main features and functions and how it can help you visualize your data. First, let's talk about some different visualization packages you can use with R. Base R has its own package, and there are other useful packages you can add. They'll help you do almost anything you want with your data, from making simple pie charts to creating more complex visuals like interactive graphs and maps. General-purpose packages like `plotly` let you do a wide range of visualization functions. Others, like `rgl`, focus on specific solutions, like 3D visuals. Some of the most popular include `ggplot2`, `plotly`, `lattice`, `rgl`, `igraphs`, `leaflet`, `highcharter`, `patchwork`, `gganimate`, and `ggridges`. Personally, `ggplot2` is my favorite for data analysis; it's both powerful and flexible. With a little bit of code, you can create all kinds of different plots. You can use `ggplot2` on its own or extend its powers with other packages. Plus, it's the most popular visualization package in R; a lot of data analysts prefer to use `ggplot2`, which is why we're using `ggplot2` here. `ggplot2` was originally created by the statistician and developer Hadley Wickham in 2005. Wickham's inspiration for creating `ggplot2` came from the 1999 book *The Grammar of Graphics*, a scholarly study of data visualization by computer scientist Leland Wilkinson. The first two letters of `ggplot2` actually stand for "grammar of graphics," and in the same way the grammar of a human language gives us rules to build any kind of sentence, the grammar of graphics gives us rules to build any kind of visual. So `ggplot2` has some basic building blocks that you can use to create plots. In other words, when you learn the basic steps for creating a plot in `ggplot2`, you can reuse these steps to create lots of different kinds of plots. Plus, you can add or remove layers of detail to your plot without changing its basic structure or the underlying data. This makes `ggplot2` really powerful. In the next video, we'll go over these steps one by one. `ggplot2` has lots of other benefits too. You can create all different types of plots, including scatter plots, bar charts, line diagrams, and tons more. You can change the colors, layout, and dimensions of your plots and add text elements like titles, captions, and labels. With just a little bit of code, you can create high-quality visuals. Plus, `ggplot2` lets you combine data manipulation and visualization using the pipe operator. `ggplot2` also has tons of functions that cover all your data vis needs. To give you an idea, check out the `ggplot2` cheat sheet, which is a popular reference guide. You can find out more about the cheat sheet in an upcoming reading. It's not important to learn all these functions right away, or even know what they are. Over time, as you get into more advanced data analysis, you can learn about new functions as you need them. Just know that if you need to find a function for something, `ggplot2` probably has it. And like we discussed, even the basic functions of `ggplot2` let you do so much. We'll focus on some core concepts in `ggplot2`: aesthetics, geoms, facets, labels, and annotations. These might be new concepts to you, and that's okay; we'll learn about them together. And soon we'll explore each in detail. For now, let's get a quick preview. In `ggplot2`, an aesthetic is a visual property of an object in your plot. For example, in a scatter plot, aesthetics include things like the size, shape, or color of your data points. Think of an aesthetic as a connection or mapping between a visual feature in your plot and a variable in your data. We'll talk more about mapping later on. A geom refers to the geometric object used to represent your data. For example, you can use points to create a scatter plot, bars to create a bar chart, or lines to create a line diagram. You can choose a geom to fit the type of data you have. Points show the relationship between two quantitative variables; bars show how one quantitative variable varies across different categories. Up next, we'll talk about the facet function. Facets let you display smaller groups or subsets of your data. With facets, you can create separate plots for all the variables in your data set. Finally, the label and annotate functions let you customize your plot. You can add text like titles, subtitles, and captions to communicate the purpose of your plot or highlight important data. That's all for now. Coming up, we'll use code to create our own first plot in `ggplot2`.

Welcome back. In this video, we'll use the Palmer Penguins data to learn how to create a plot in `ggplot2`. Earlier, I used this data to give you a preview of what `ggplot2` can do. You might remember that the penguins dataset contains size measurements for three penguin species that live in the Palmer Archipelago in Antarctica. The data set includes variables such as body mass, flipper length, and bill length. Now we'll learn how to use code to create those visuals. We'll go through the process of creating a plot step by step. We'll also go over some general tips on how to write code in `ggplot2` and check out some useful help resources. First, let's log into RStudio Cloud. As we go along, I encourage you to join in and try out all the code in RStudio. Feel free to pause the video anytime you need to. We're assuming you already have the tidyverse packages installed. If you don't, refer to an earlier video or run `install.packages("tidyverse")`. Let's start by loading the `ggplot2` package and the penguins dataset. Let's check out the plot that shows the relationship between body mass and flipper length in the three penguin species. The plot shows a positive relationship between the two variables; in other words, the larger the penguin, the longer the flipper. Now let's check out the code. The code uses functions from `ggplot2` to plot the relationship between body mass and flipper length. As a quick refresher, in R, a function's a name followed by a set of parentheses. Lots of functions require special information to do their jobs; you write this information, called the function's argument, inside the parentheses. The three functions in the code are the `ggplot` function, the `geom_point` function, and the `aes` function. Every `ggplot2` plot starts with the `ggplot` function. The argument of the `ggplot` function tells R what data to use for your plot, so the first thing to do is choose a data frame to work with. You can set up the code like this: inside the parentheses of the function, write the word `data`, then an equal sign, then `penguins`. This code initializes, or starts, the plot. If we stop right now and run the code, the result will be an empty plot. Let's try it. This is just the first step in creating a plot. The next thing you might notice about this code is the plus sign at the end of the first line. You use the plus sign to add layers to your plot. In `ggplot2`, plots are built through combinations of layers. First, we start with our data, then we add a layer to our plot by choosing a geom to represent our data. The function `geom_point` tells R to use points to represent our data. Keep in mind that the plus sign must be placed at the end of each line to add a layer. Adding a geom function is the second step in creating a plot. As a reminder, a geom is a geometric object used to represent your data. Geoms include points, bars, lines, and more. In our code, the function `geom_point` tells R to use points and create a scatter plot. We'll learn more about geoms later on. Next, we need to choose specific variables from our data set and tell R how we want these variables to look in our plot. In `ggplot2`, the way a variable looks is called its aesthetic. As a quick reminder, an aesthetic is a visual property of an object in your plot, like its position, color, shape, or size. The `mapping = aes` part of the code tells R what aesthetics to use for the plot. You use the `aes` function to define the mapping between your data and your plot. Mapping means matching up a specific variable in your data set with a specific aesthetic. For example, you can map a variable to the x-axis of your plot, or you can map a variable to the y-axis of your plot. In a scatter plot, you can also map a variable to the color, size, and shape of your data points. We'll learn more about aesthetics soon. Mapping aesthetics to variables is the third step in creating a plot. In our code, we map the variable flipper length to the x-axis and the variable body mass to the y-axis. Inside the parentheses of the `aes` function, we write the name of the aesthetic, then the equal sign, then the name of the variable. We write the code, and R takes care of the rest. Using the penguins data, R creates a scatter plot, puts the variable body mass on the y-axis, and the variable flipper length on the x-axis. Our code follows the common sequence for creating plots in `ggplot2`. Earlier we talked about the grammar of graphics, a set of steps for making all kinds of different plots. You can also think of the sequence as the basic grammar for making plots in `ggplot2`. To create a plot, follow these three steps: start with the `ggplot` function and choose a data set to work with; add a `geom_` function to display your data; map the variables you want to plot in the arguments of the `aes` function. We can also turn our code into a reusable template for creating plots in `ggplot2`. To make a plot, replace the bracketed sections in the code with a dataset, a `geom_` function, or a group of aesthetic mappings. We can make all kinds of different plots using this template. For example, instead of plotting the relationship between body mass and flipper length, we could use two different variables in the penguins data set. Let's try bill length and bill depth. We can put bill length on the x-axis and bill depth on the y-axis. Let's run the code and check out this new...

Scatter plots: As you learn to write code in R, or any other programming language, you'll come across problems. It happens to everyone. I've been working in R for years, and I still write code that has errors. A lot of times, these will be minor errors with easy fixes. It helps if you pay attention to the details. For example, R is case-sensitive. If you accidentally capitalize the first letter in a certain function, it might affect your code. Also, make sure every opening parenthesis in your function matches with a closing parenthesis. Notice how this code won't run correctly, but this code does.

One common problem when working with ggplot2 is remembering to put the plus sign in the right place when adding a layer to your plot. Always put the plus sign at the end of a line of code. It's easy to forget and put it at the beginning of the line. You might accidentally use a pipe instead of a plus sign. We all make mistakes; that's part of the learning process. The good news is we have plenty of tries to get it right. There's also plenty of resources to help you out. To learn more about any R function, just run the code `?function_name`. For example, if you want to learn more about the `geom_point` function, type in `?geom_point`. As a new learner, you might not understand all the concepts in the help page. At the bottom of the page, you can find specific examples of code that may show you how to solve your problem. If you still can't find what you're looking for, feel free to reach out to the R community online. As we mentioned earlier, there are tons of great online resources for R. Chances are someone else has had the same problem.

That's it for now. Up next, we'll learn more about aesthetics. See you soon.

Hello, my name is Joseph. I'm a People Analyst at Google. As a People Analyst, my job is to work with executives and HR business partners to use data to make informed people decisions. So my journey to People Analytics is very unique, one coming from an industry school in New York and going to school in Syracuse, which was a private school. The transition was very different in terms of the regular academically and also the social level that I was competing with, and just being completely honest, I did feel like I didn't belong there. I felt the imposter syndrome each and every day, and my first semester I was struggling with my academics because of this lack of strong foundation that I had. Every time I finished my classes, I was seeking for tutoring opportunities, so I was working three times or four times more than my peers. But in the long run, I actually came to a point where I was doing much better than my peers, and I was one actually, you know, teaching them, also tutoring them on their homeworks.

When I was going to college my freshman year, I wanted to major in computer engineering. But unfortunately, coming from a family of immigrants who did not know what computer engineering was or even saw someone in our community who has, you know, really succeeded in that, they really discouraged me from pursuing this path again because they didn't want to take the risk. Unfortunately, I switched my major from computer engineering into undecided. Fortunately for me, uh, two years later, I found another Black friend of mine who was also an immigrant African who was majoring in information technology. And just by me learning from his experience and the classes he was taking, it really got me really interested in the field. I took one introductory class, and I really succeeded in that.

Prior to Google, I used to work at a company called Accenture, where I was a consultant doing custom analytics. So towards the end of my second year at the company, I went to a job fair where Google was recruiting there, so I spoke to the recruiter, and she mentioned to me about this new practice called People Analytics, which is very similar to what I was doing at Accenture. I just went back home, did my research, and from there I was really interested in the space that I wanted to definitely develop my career in. So since I started at Google, I just will also honestly say that it was very challenging in terms of the rigor and the difficulties of the work that we were doing. So the first thing that I did was I sought for mentors I knew were interested in my career development and also an advocate for myself. So by talking to them and just learning a few lessons from them as a way to better maneuver through this space, I first gained a lot of courage and also was motivated to even learn beyond the work environment.

The second thing is that I want to make sure that I'm constantly learning and also leveraging my peers as a resource. So whenever I do get analysis that I need a second opinion on, I turn to my teammates who will just make sure they give me the encouragement I need or a second opinion for me to better enhance my analysis. And I believe the third thing that I always do is that I seek for stretch opportunities, right? So, for example, I know that there's a space that I'm blocking and that I need to develop; I make sure that I ask my manager that, hey, I know that I struggle in this space, how can I actually grow in this area by giving me more work that will allow me to develop that skill set? So I would say that's a mix of acknowledging that you see a gap in your personal development and also working towards improving that by leveraging the resources around you and just working towards that goal to improve yourself each and every single day and also every year as well.

Hello again. In this video, you'll learn how to change the aesthetics of your visuals, which can help you present your data in a more compelling way. With aesthetics, you can highlight key points in your data and communicate more clearly and effectively with your stakeholders. Earlier, we learned that an aesthetic is a visual property of an object in your plot. For example, in a scatter plot, aesthetics include the size, shape, or color of your data points. You can display a point in different ways by changing its aesthetics, or the way it looks. You can make a point small, triangular, or blue, or a combination of these.

Let's go back to our penguins data set and review the code for our plot that shows the relationship between body mass and flipper length. As a quick refresher, the `mapping = aes` part of the code tells R what aesthetics to use for the plot. You use the `aes` function to define the mapping between your data and your plot. Mapping means matching up a specific variable in your data set with a specific aesthetic. For example, you can map a variable to the x-axis of your plot, or you can map a variable to the y-axis of your plot. To map an aesthetic to a variable, set the name of the aesthetic equal to the name of the variable inside the parentheses of the `aes` function. Our code tells R to map flipper length to the x-axis and body mass to the y-axis. Let's log into RStudio Cloud and run the code. As a quick reminder, let's start by loading the ggplot2 package and the penguins data set. R will automatically place the appropriate label on each axis of our scatter plot after you map a variable to an aesthetic. R takes care of the rest. You can also map data to other aesthetics like color, size, and shape. Right now, our plots are in black and white. It clearly shows the positive relationship between the two variables: as the values on the x-axis increase, the values on the y-axis increase. But it's also got some limitations. For example, we can't tell which data points refer to each of the three penguin species. To solve this problem, we can map a new variable to a new aesthetic. Let's add a third variable to our scatter plot by mapping it to a new aesthetic. We'll map the variable `species` to the aesthetic `color` by adding some code inside the parentheses of the `aes` function. We'll add a comma after the `body_mass` variable and type `color = species`. Our code tells R to assign a different color to each species of penguin. Let's check it out. The gentoos are the largest of the three penguin species. The legend, just to the right of the plot, shows us that the blue points refer to the gentoo penguins. Not only does R automatically apply different colors to each data point, it also gives a legend to show us the color coding; that's what I love about R. Give it just a little bit of code, and it'll go the extra mile to help you out.

We can also use `shape` to highlight the different penguin species. Let's map the variable `species` to the aesthetic `shape`. To do this, we can change the code from `color = species` to `shape = species`. Instead of colored points, R assigns different shapes to each species. Now the legend shows us a circle for the Adelie species, a triangle for the Chinstrap, and a square for the Gentoos. You might notice that our plots are in black and white again because we removed the code for color. Let's put some color back into our plot. If we want, we can map more than one aesthetic to the same variable. Let's map both `color` and `shape` to `species`. We'll add the code `color = species` while keeping the code `shape = species`. Now our plot shows a different color and a different shape for each species. We can keep going. Let's add `size` as well and map three aesthetics to `species`. If we add `size = species`, each colored shape will also be a different size. Using more than one aesthetic can also be a way to make your visuals more accessible because it gives your viewers more than one way to make sense of your data. We can also map `species` to the `alpha` aesthetic, which controls the transparency of the points. Our first plot showed the relationship between body mass and flipper length in black and white. Then we mapped the variable `species` to the aesthetic `color` to show the difference between each of the three penguin species. If we want to keep our graph in black and white, we can map the `alpha` aesthetic to `species`. This will make some points more transparent, or see-through, than others. This gives us another way to represent each penguin species. Let's try it. `alpha` is a good option when you've got a dense plot with lots of data points.

You can also set the aesthetic apart from a specific variable. Let's say we want to change the color of all the points to purple. Here, we don't want to map `color` to a specific variable like `species`; we just want every point in our scatter plot to be purple. So we need to set our new piece of code outside of the `aes` function and use quotation marks for the R color value. This is because all the code inside of the `aes` function tells R how to map aesthetics to variables; for example, mapping the aesthetic `color` to the variable `species`. If we want to change the appearance of our overall plot without regard to specific variables, we write code outside of the `aes` function. Let's write the code and run it. That's all for now. We just learned about the most common aesthetics for points: x, y, color, shape, size, and alpha. We also discovered how aesthetics can change the look of our plot and highlight important data. We've covered a lot so far and learned a bunch of new concepts. It takes time to process new information and learn new skills, so feel free to watch any of these videos again if you need a refresher or want to practice in RStudio. Coming up, we'll learn more about geoms. See you then.

Great to see you again. In this video, we'll learn how to use different geom functions to create different types of plots, such as scatter plots and bar charts. There are lots of different geoms available. You can choose a specific geom based on how you want to represent your data and your goals for communicating it. This lets you tell the story of your data in different ways and communicate effectively to different audiences. Let's start with two visualizations. Both visuals contain the same x variable and the same y variable; both use the same data, but each plot uses a different visual object to represent the data. One uses points; the other uses a smooth line. In other words, they use different geoms. In ggplot2, a geom is the geometrical object used to represent your data. Geoms include points, bars, lines, and more. The `geom_point` function uses points to create scatter plots; the `geom_bar` function uses bars to create bar charts, and so on. To change the geom in our plot, we need to change the geom function in our code. For example, take the plot that shows the relationship between body mass and flipper length. The code uses `geom_point` to create a scatter plot. Let's log into RStudio Cloud and watch what happens when we change geoms. First, let's load the ggplot2 package and the penguins data set. Now we can put `geom_smooth` in place of `geom_point`. We still have the same data, but now the data's got a different visual appearance. Instead of points, there's a smooth line that fits the data. The `geom_smooth` function is useful for showing general trends in our data. The line clearly shows the positive relationship between body mass and flipper length: the larger the penguin, the longer the flipper. We can even use two geoms in the same plot. Let's say we want to show the relationship between the trend line and the data points more clearly. We can combine the code for `geom_point` and the code for `geom_smooth` by adding a plus symbol after `geom_smooth`. Let's write the code and run it. Let's say we want to plot a separate line for each species of penguin. We can add the `linetype` aesthetic to our code and map it to the variable `species`. `geom_smooth` will draw a different line with a different line type for each species of penguin. The legend shows how each line type matches with each species. The plot clearly shows the trend for each species.

Finally, let's check out the `geom_jitter` function. The `geom_jitter` function creates a scatter plot and then adds a small amount of random noise to each point in the plot. Jittering helps us deal with overplotting, which happens when the data points in a plot overlap with each other. Jittering makes the points easier to find. I'll show you what I mean. Let's replace `geom_point` with `geom_jitter`. Now that we've seen what ggplot2 can do with scatter plots, let's explore bar charts. We'll use the `diamonds` data set that you're already familiar with. This includes data like the quality, clarity, and cut for over 50,000 diamonds. This data set comes with the ggplot2 package, so it's already loaded. To make a bar chart, we use the `geom_bar` function. Let's write some code that plots a bar chart of the variable `cut` in the `diamonds` data set. `cut` refers to a diamond's proportions, symmetry, and polish. Notice that we didn't supply a variable for the y-axis. When you use `geom_bar`, R automatically counts how many times each x value appears in the data and then shows the counts on the y-axis. The default for `geom_bar` is to count rows, but that's only one of the many different applications for bar charts. For example, the x-axis of our plot shows five categories of cut quality: Fair, Good, Very Good, Premium, and Ideal. The y-axis shows the number of diamonds in each category. Over 20,000 diamonds have a value of Ideal, which is the most common type of cut. `geom_bar` uses several aesthetics that you're already familiar with, such as color, size, and alpha. Let's add the `color` aesthetic to our plot and map it to the variable `cut`. We write the code the same way as we did with scatter plots and add `color = cut` after `x = cut`. Don't forget to put a comma after `x = cut` to add a new aesthetic. The `color` aesthetic adds color to the outline of each bar. R also supplies a legend to show the color coding. Let's say we want to highlight the difference between cuts even more clearly. To make our plot easier to understand, we can use the `fill` aesthetic to add color to the inside of each bar. In our code, we put `fill = cut` in place of `color = cut`. R automatically chooses the colors and supplies a legend that looks great. I really enjoy using the `fill` aesthetic. If we map `fill` to a new variable, `geom_bar` will display what's called a stacked bar chart. Let's map `fill` to `clarity` instead of `cut`. Our plot now shows 40 different combinations of cut and clarity; each combination has its own colored rectangle. The rectangles that have the same `cut` value are stacked on top of each other in each bar. The plot organizes the complex data. Now we know the difference in volume between cuts, and we can figure out the difference in clarity within each cut. This is just the beginning of what you can do with geoms. Ggplot2 has over 30 geom functions that you can use to make plots, and extension packages give you even more. The ggplot2 cheat sheet is a great resource for learning more about geoms. As you move forward and do more advanced data analysis, you'll find plenty of new geoms to work with. Until then, the geoms we just reviewed will keep you busy and let you do a lot with your data. Coming up, we'll learn how to use the facet functions to display our data in different ways. Bye for now.

Welcome back. In this video, we'll learn how to use the ggplot2 facet functions to display your data in new ways. Facet functions let you display smaller groups or subsets of your data. A facet is a side or section of an object, like the sides of a gemstone. Facets show different sides of your data by placing each subset on its own plot. Faceting can help you discover new patterns in your data and focus on relationships between different variables. For example, let's say you're looking at sales data for a clothing company. You might want to break down your data by category to show specific trends: children's clothing versus adult clothing, or spring fashions versus fall fashions. Or if you are running an employee engagement survey, you might want to break down your data by tenure and compare senior employees to new employees. Ggplot2 has two functions for faceting: `facet_wrap` and `facet_grid`. Let's explore them both. We'll start with `facet_wrap`. To facet your plot by a single variable, use `facet_wrap`. Let's say we wanted to focus on the data for each species of penguin. Take our plot that shows the relationship between body mass and flipper length in each penguin species. The `facet_wrap` function lets us create a separate plot for each species. To add a new layer to our plot, we'll add a plus symbol to our code. Then, inside the parentheses of the `facet_wrap` function, type a tilde symbol followed by the name of the variable. Let's log into RStudio Cloud and check it out. As a reminder, we'll start by loading the ggplot2 package and the penguins data set. You can find the tilde symbol in the upper left corner of your keyboard, just below the escape key. There, the separate plots show the relationship between body mass and flipper length within each species of penguin. Pretty cool, right? Facets help us focus on important parts of our data that we might not notice in a single plot. If your visual is too busy, for example, if it's got too many variables or levels within variables, faceting can be a good option. Let's try faceting the diamonds data set. Earlier, we made a bar chart that showed the number of diamonds for each category of cut: Fair, Good, Very Good, Premium, and Ideal. We can use `facet_wrap` on the `cut` variable to create a separate plot for each category of cut. Let's check it out.

To facet your plot with two variables, use the `facet_grid` function. `facet_grid` will split the plot into facets vertically by the values of the first variable and horizontally by the values of the second variable. For example, we can take our penguins plot and use `facet_grid` with the two variables `sex` and `species`. In the parentheses following the `facet_grid` function, we write `sex`, then the tilde symbol, then `species`. Let's run the code. There are nine separate plots, each based on a combination of the three species of penguin and three categories of sex. `facet_grid` lets you quickly reorganize and display complex data and makes it easier to spot relationships between different groups. If we want, we can focus our plot on only one of the two variables. For example, we can tell R to remove `sex` from the vertical dimension of the plot and just show `species`. Let's check it out. You can easily spot differences in the relationship between flipper length and body mass between the three species. In the same way, we can focus our plot on `sex` instead of `species`. Facets let you reorganize your data to show...

specific relationships between variables and reveal important patterns and trends in subsets of your data. That's all for now. Next up, we'll learn how to customize our plots using labels and annotations. Until next time.

Hi, great to have you back. Coming up, we'll learn how to customize the look and feel of our plots using the label and annotate functions. In everyday language, to annotate means to add notes to a document or diagram to explain or comment upon it. In ggplot2, adding annotations to your plot can help explain the plot's purpose or highlight important data. When you present your data visuals to stakeholders, you may not have much time to meet with them. Labels and annotations will point their attention to key things and help them quickly understand your plot.

Let's start with the label function. It's super useful for adding informative labels to a plot, such as titles, subtitles, and captions. For example, we can add a title to our plot that shows the relationship between body mass and flipper length for the three penguin species. A title will clearly indicate the purpose of the plot. Let's go over the code. First, we add a plus sign to add a new layer to our plot. Next, in the parentheses following the label function, we write the word title, then an equal sign, then the specific text we want in our title. Let's log into our studio cloud and check it out. First, let's load the ggplot2 package and the penguins dataset. Remember, put the plus sign at the end of a line of code; it's easy to forget. R automatically displays the title at the top of the plot.

We can also add a subtitle to our plot to highlight important information about our data. To do this, we enter the code for a subtitle in the same way as a title. Remember to add a comma after the title argument before you enter your subtitle. R automatically displays the subtitle just below the title. We can add a caption to our plot in the same way. Captions let us show the source of our data. The Palmer penguins data was collected from 2007 to 2009 by Dr. Kristin Gorman, a member of the Palmer Station Long-Term Ecological Research Program. Let's cite Dr. Gorman in our caption. R automatically displays the caption at the bottom right of our plot. Titles, subtitles, and captions are labels that we put outside of the grid of our plot to indicate important information.

If we want to put text inside the grid to call out specific data points, we can use the annotate function. For example, let's say we want to highlight the data from the gentoo penguins. We can use the annotate function to add some text next to the data points that refer to the gentoos. This text will clearly communicate what the plot shows and reinforce an important part of our data. Okay, let's check out the code. In the parentheses of the annotate function, we've got information on the type of label, the specific location of the label, and the context of the label. In this case, we want to write a text label. We also want to place it near the gentoo data points. Let's put it at the following coordinates: x-axis equals 220 millimeters and y-axis equals 3500 grams. Finally, let's write our text: "The gentoos are the largest." Let's run it; check it out. R automatically places the text label on the correct coordinates in our plot.

We can customize our annotation even more. Let's say we want to change the color of our text; well, we can add color equals followed by the name of the color. Let's try purple. We can also change the font style and size of our text; use fontface and size to write the code. Let's bold our text and make it a little larger. We can even change the angle of our text. For example, we can tilt our text at a 25-degree angle to line it up with our data points. Let's try it; that looks great. By this point, our code is getting pretty long. If you want to use less code, you can store your plot as a variable in R. As a quick reminder, to create a variable in R, you type the variable name, then a less than sign followed by a dash. Let's try it with the variable name p. Now, instead of writing all the code again, we can just call p and add an annotation to it like this. You get the same result. Some people like to see every step of their code listed out in front of them, so there are advantages to doing it the longer way. It's really up to you; I just want you to know that you've got options. Hopefully, this gives you an idea of some of the ways you can customize your plots. Labels and annotations can be really helpful when it comes to highlighting important parts of your data and communicating key points. That's all for now. Coming up, you'll learn some useful ways to save your plots in ggplot2. See you next time.

Hi and welcome back. In this video, we'll learn how to save our plots. Saving your work so that you can access it later is so important. It lets you continue to work on it yourself or share it with others. Being able to reproduce and share your work is a key part of your future analyst role because it lets you collaborate with teammates. They can double-check your work and offer feedback to help you improve it. So let's save our plots. To do this, you'll use the export option in the plots tab of RStudio or the ggsave function provided by the ggplot2 package. First, we'll save our plots using the export option. Then we'll use the ggsave function. Let's log into RStudio Cloud. We'll load the ggplot2 package and the penguins dataset. To start, let's write some code and create the plot that shows the relationship between body mass and flipper length in three penguin species. Let's use the export option in the plots tab to save our plot. We can save it as an image file or a PDF file. Let's try saving it as an image. There are six different options for image format, including PNG and JPEG. Let's try PNG. Next, we name our file and click save. Now, if we click on the files tab, we'll find our file in the list. Let's open it up; looks great. That covers the export option for saving a plot. Now let's check out the ggsave function.

Ggsave is a useful function for saving a plot. It defaults to saving the last plot that you displayed and uses the size of the current graphics device. Let's try saving our plot as a PNG file using ggsave. Ggsave will automatically save the plot that shows the relationship between body mass and flipper length because this is the last plot that we displayed. We have to give the file a name and say what kind of file we want to save it as. Let's write the code. Within the parentheses of the function, we start off with a quotation mark, followed by the name of the file. Let's name it "three penguin species". We put a period after the file name, then the type of file we want, then a closing quotation mark. Let's run it. Now, if we click on the files tab, we'll find our new file in the list. Let's open it up again; looks great. That covers the basics of saving plots. After all your hard work creating plots in ggplot2, you definitely want to remember to save them so you can access and share them later on. And that's the end of our work on data visualization. You're off to a great start visualizing data with ggplot2. Plus, the concepts we've covered are a great base for learning even more about dataviz and R as you move forward. We started off by learning the basic steps for creating plots in ggplot2. From there, we learned how aesthetics can change the look of our plots and highlight important parts of our data. We used different geoms to create different types of plots, like scatter plots and bar charts, and used facet functions to show subsets of our data. Then we customized our plots with labels and annotations. Finally, we learned how to save all our hard work so we can access and share it later on. That's a lot of ground we covered. Feel free to review the videos anytime you want and move at your own pace. It takes lots of time and practice to become familiar with new concepts and to develop new skills. No one gets everything right the first time around, but the more you practice, the more you'll start to feel at home in ggplot2. If it doesn't always feel easy, that's okay; that just means your mind is expanding and your skill set's getting bigger. Trust me, it's worth it. Learning ggplot2 is a game changer for anyone interested in visualizing data. I hope you enjoyed it as much as I did. I love creating visuals in ggplot2. Coming up, you'll learn how to document and report your data using R. Until next time.

Hi and welcome back. We've covered a lot in our time working in R. We've learned the ins and outs of R and RStudio, including how to analyze and visualize your data. Now you'll learn how to document and report your work using R Markdown. R Markdown is a file format for making dynamic documents with R. You can use an R Markdown file as a code notebook to save, organize, and document your analysis using code chunks, comments, and other features. When you finish your data cleaning and exploration, you can create a report in R Markdown to summarize your findings for stakeholders. The core of the work we do in my department involves analytics. When my team started getting bigger, we noticed we didn't have a shared language for data analysis, so there was an effort for everyone to learn R so we could collaborate more easily. Now everyone speaks the same programming language. We can review each other's code, which has led to more consistency and collaboration and better analysis. R Markdown reports are great for sharing knowledge. These reports let anyone, from a small group of online users to a large company, share and reproduce analysis. In this course, we'll start with an overview of R Markdown, and then we'll learn how to install R Markdown in RStudio. After that, we'll check out how to create an R Markdown document. We'll also explore the structure and components of the document so you'll have an idea of how to use them to record and report your analysis. Next, we'll show you how to insert and edit pieces of code, called chunks, into your document. And finally, we'll check out the process of exporting your documentation. It's always good to have a report of the analysis you've done, both for yourself and your stakeholders. After that, we'll wrap up our time with R. Of course, your time with R can keep going, and you can keep practicing. I hope you put R to good use in your future job as a data analyst, too. It's a huge advantage in your career. Speaking of your career, when you've completed everything in the R program, you'll have the chance to add to or start building your portfolio by completing a case study. This is a great way to showcase all the skills you've learned so far and stand out to future employers. We'll talk more about this project later. In the meantime, let's get back into the R groove. See you soon.

Hi again. As a data analyst, you'll need to refer to your analysis at a moment's notice. You might need to share it with your fellow team members, or a stakeholder might ask about one of your conclusions. Documenting your work makes it easy to quickly share your analysis with anyone, and that's where R Markdown comes in. Earlier, we learned that R Markdown is a file format for making dynamic documents with R. R Markdown lets you create a record of your analysis and conclusions in a document. It ties together your code and your report so you can share every step of your analysis, and the best part is you don't even have to leave RStudio to do this. This document will help stakeholders and team members understand what you did in your analysis to reach your conclusions. Their feedback will also help you improve your analysis. R Markdown documents are written in Markdown. Markdown is a syntax for formatting plain text files. Using Markdown makes it easier to write and format text in your document. Markdown is also easy to read and to learn. For example, if you want to italicize a word or phrase in Markdown, just add a single underscore or asterisk right before and after the word. When you create a report of the document, the Markdown formatting is no longer visible, just the word or phrase in italics. We'll show you more formatting options soon, but they're all similar to this example. Basically, they're simple enough to let you focus on descriptions and explanations of your analysis without having to think too much about how to format them. Besides text, R Markdown also includes an interactive option called an R Notebook that lets users run your code and show the graphs and charts that visualize the code. Any R Markdown document can be used as a notebook. This creates a clear overall picture of your analysis and conclusions. R Markdown lets you convert your files into lots of different formats, too. You can create HTML, PDF, and Word documents, or you can convert to a slide presentation or dashboard. Having these options makes it easy to share the same analysis in a variety of ways, depending on your audience. The Markdown language was originally designed for HTML output. HTML is the set of markup symbols and codes used to create a web page. R Markdown has the most available features for this format, but you can get good results in any of the formats. While R Markdown is a great way to record and share your analysis, there are other options, too. Notebooks like Jupyter, Kaggle, and Google Colab do a lot of the same things as an R Markdown notebook, including the interactive elements. You'll read more about these options in a little bit. Coming up, we'll create an R Markdown document. You'll get to see this effective analysis tool in action. See you soon.

Welcome back. Exploring the different tools available for analysis is one of the more fun parts of being a data analyst. By now, you've had the chance to try out tools like spreadsheets, BigQuery or other SQL tools, and Tableau. Now we'll check out a tool you can use in RStudio: R Markdown. As a reminder, R Markdown is a great tool for documenting your analysis at any stage, but especially when you've completed a project. Let's open up RStudio and get started with R Markdown. Feel free to follow along with the video and try it out on your own later, or go ahead and join us now in your own RStudio account. We'll first install the R Markdown package by using our install.packages function and "rmarkdown" in parentheses. As a reminder, installing packages can take some time; bright red text may show up in your console as it installs; that's all perfectly normal. Okay, let's open up a new R Markdown, or .Rmd, file using the file menu. If you're working along with us and you're prompted to install packages that you'll need to open your file, go ahead and click yes right away. You might notice some of the outputs available in R Markdown. For now, we'll use the default HTML and document options. The other output options will also be available later. We'll add a file name and author and then open our file. Next, we'll save it so we can use it later. So now we have an .Rmd file filled with metadata at the top and chunks of code in the gray sections. There's text in between for explaining the code and adding comments on your analysis and conclusions. This is an R Markdown document in its original format. It's definitely useful and can be edited and added to, but if we want to produce a report containing all text, code, and results, we need to click the Knit button. Now we've got the report; it's an HTML file that you can share with others. Let's compare the original .Rmd file with the HTML report. You can tell that the text has been transformed into a more viewer-friendly format. Also, the code chunks have all been run, and we now have their output, both the columns of data and the plot from an analysis on the cars dataset. The report's clear and formatted in a way that's easy to follow and understand. We could share it with stakeholders even if they've got no experience in R. R Markdown files are definitely an effective way to complete the data analysis process. You can start your analysis in R and create a report complete with code and visualizations all in the same workspace. Coming up, we'll show you more examples of how to use R Markdown to make your documentation even more effective. Bye for now.

Hello there. Earlier, we showed you how to get started using R Markdown. We created a Markdown document, called an .Rmd file, which is super useful for making and saving a final report that summarizes your data exploration and analysis findings. In this video, we'll check out the structure of the text in an .Rmd file and how you could format it to better organize and emphasize your findings. Let's go into RStudio and open the file we saved earlier called "R Markdown Intro". If you're working along with us and don't have a file saved, you can open up a new R Markdown, or .Rmd, file using the file menu. If you're prompted to install packages, go ahead and click yes. Click OK to open with the default options, and then save your file. Now let's dig deeper into this file. We'll start at the top; this is the YAML header section. YAML is a language for data that translates it so it's readable. Fun fact: YAML originally stood for "Yet Another Markup Language". This section is called out using three dashes on the first and last lines. This syntax automatically creates the YAML header section when it's used in an .Rmd file. In an .Rmd file, this section is basically for metadata, or the data about the data in the rest of the file. The title, author, date, and file type of an output are automatically included when you create a new file. There's lots of different functions and formatting options in this section. For now, just make sure you have at least the four details we've got in our file. Now you can use the template that appears when you open the file and just edit over it, or you can start from scratch using the three dashes to create the YAML section and the rest of the contents in the file. We'll cover these steps over the next few videos and in the other program resources.

Next, let's check out the text in the white areas of our file. Think of the text as a way to comment on and explain your code and analysis and any visualizations you're including. You can format the text to include links, ordered lists, equations, and more. The text is formatted using Markdown, the syntax we introduced earlier. We've included a reading that shows you all of the ways to format text, as well as lots of other great Markdown tips and tricks. You'll also learn some more formatting examples in the next video. For now, let's try some examples that are in this file. On line 12, there's two hashtags and a space before the words "R Markdown". Hashtags are used for headers; the more hashtags, the smaller the header. The space is important as well; otherwise, RStudio won't recognize that this is a header. Let's knit our file again. There's the R Markdown header in the HTML file. If we add two more hashtags in the .Rmd file and click Knit once again, the output changes; the header is now smaller. We'll change it back because the original format made sense. Since this header is introducing information about R Markdown that comes in the next two paragraphs, we want to emphasize it. In the first paragraph of this section, there's a brief summary of Markdown. There's a link in the text, and it's formatted using angle brackets. Using these brackets results in a clickable link in the output; that's a handy feature if you want to refer to any helpful links or include them as sources for your analysis. In the next paragraph, "Knit" is set off with two asterisks on either side of the word. This bolds the word; using one asterisk on either side would instead italicize the word. Let's scroll down to the last paragraph. Here we've got some inline code, which can be inserted directly into the text of a .Rmd file. The code appears in a gray box like the code chunks we'll talk about soon. Using inline code like this lets you refer to the code directly as you explain it. Let's knit our file one more time. All the formatting works together to make a well-designed, readable file that's easy to share with stakeholders and team members. That's it for now, but there's lots more to learn about creating your own reports. Stay tuned.

I'm Meg, and I'm a Product Lead at Google. As a Product Lead, I work with designers and web developers to build features that our users will love. Specifically, I work for Kaggle, which is an online data science community for people who are learning data science and machine learning. So we get to build exciting features that help people learn from data and advance in their careers. I work with designers and researchers.

To do studies to understand what our users want and what they need in the product, and I work with engineers to figure out exactly how to write out those requirements for the features that we decide to build. Learning any programming language is really empowering because your only limits are your creativity and your curiosity. It's really the curiosity that I have about the world that led me to research and data analysis, especially with R. Just felt it was really freeing to be able to ask a question about the world and know how I could work with data to get an answer to that question.

The second thing that I think is really exciting and empowering about knowing a programming language is the transferable skills that it gives you. And then the last thing I think is really exciting is really the, like, community and ecosystem that comes along with it. R is really no exception when it comes to that; in fact, I think R's community is really outstanding. And to have the community and that public ecosystem of resources right at your fingertips is really going to supercharge what you can do with data as a data analyst, and I think that's super exciting.

It's completely normal to feel intimidated or confused or kind of stuck as you're first learning R. There are things that are kind of quirky about the language, and you know, it's not your fault; you know, you just kind of have to get past those things. And I can promise that things will make a lot more sense, especially once you're able to start using the tidyverse. I would say, you know, stick with it, and the other, you know, kind of piece of advice I'd have is try to connect with the R community as early as possible in your R learning journey.

The thing that's just fantastic about R is the fact that its community is really vibrant, it's really welcoming, and you're going to find things like people who are expert practitioners in R who are, you know, sharing their kind of like their mistakes, and they'll, they're willing to share their kind of like learning journey as well. And I think it'll really help you see that, you know, you're not alone. I definitely had these moments where I was pretty frustrated when I was first learning R. When it really clicked for me was when I had the opportunity to use R to answer my own personal research questions. That is when you feel like you have a personal vested interest in the outcome of your analysis; that feeling of like reward and satisfaction when you push through is, you know, something that can help really build that like momentum to keep learning.

Great to see you again. As we've explored R Markdown, we've learned how the interactive elements work: when you change something in your Rmd file, RStudio automatically applies it to your report. In this video, we'll show you a few more formatting options for making your report more complete and dynamic. Let's go back once again to our .Rmd file called "R Markdown Intro." We'll make some edits, add some elements, and then convert it to an HTML document. We'll start by adding bullets, just like in a standard document. Bullets can help you organize your content. In our file, we'll turn the list of the documents that our Markdown can author into bullet points. We use asterix in the .Rmd file to create the bullets in the output document. We'll revise this section so that the bullet points are set up in the right way.

Now let's check out a different way to include a link in the file. When you're writing a report, you might want to link to the company website or to pages you used for research. Right now, in the first paragraph, we have the website URL inside of angle brackets to embed the link in text. Instead, let's change the formatting. We'll start by changing the text to better fit the embedded link. Then we'll add square brackets and the word we want to embed the link in, and we'll change the angle brackets around the URL to parentheses. Both types of links work great, but some URLs are long and might clutter your report. In those cases, embedding links saves space and can look cleaner.

Let's say you want to embed an image too. Images are good for showing your workflow or displaying visualizations you want to reference in your report, or maybe you just want to add a GIF or another fun image. That's great, just make sure your stakeholders will appreciate it. Let's go ahead and have some fun with this example. We'll embed an image with the plot example; then we'll add an exclamation point and a caption for the image in square brackets. Next, we'll copy the URL for our image and paste it inside parentheses.

Now let's check out our finished product. We'll view it in our browser; that way, when we click the embedded link, it opens up in a new tab in the same browser. Here's our bullet points and our image and caption, and here's our embedded link, which we can click to open the website. And there's lots more ways to format an Rmd file to get it ready to turn into a complete, organized, and effective report.

While reports are a key part of presenting your analysis to stakeholders, they can be just as important for your own learning. You can use .Rmd documents to keep track of your learning by including notes and linking to online resources. You can embed useful images and add bullet points too. Speaking of learning, let's find out more about code chunks and Rmd files in the next video. See ya!

Hi again. We've learned a lot about R Markdown, or Rmd files, and how they can be formatted and converted into reports for stakeholders. We've also explored the YAML header and its comments, descriptions, and explanations for the analysis shown in the report. Now comes the heart of an Rmd file: the code. Code added to a .Rmd file is usually called a code chunk. We've shown you these code chunks in some of the RStudio sessions we've been running, and you may have noticed code chunks if you've been practicing along with us. Now we'll show you what they're all about.

Earlier, we worked with the Palmer Penguins dataset. We ran some code to analyze the data and create visualizations. After this step, we'd probably want to set up a practice report with notes about our analysis. We'll do that here and incorporate some code and visuals. Let's start by opening up RStudio and then the script with our programming, the ggplot_hook file. You can follow along using the link in the previous reading. We could share this file directly with others, but it's not very effective; it's hard to read and doesn't always include any takeaways. So we'll create a new .Rmd file instead. We'll add a title and author.

Now we have two tabs in our script pane; we can toggle between them just like with browser tabs. We'll save our new .Rmd file. This file's in the template format, so we'll delete everything except the header section and start our own. We already set up the header section, so we don't need to make any changes there. Instead of deleting, we could make edits section by section, adding our own comments and code along the way, but deleting the file contents gives us a blank space to work in and helps us avoid potential errors from mixing our own comments and code with the pre-existing ones in the template.

Before we add any code, we want to describe its purpose. The first code chunk will set up our R environment by loading our packages using the library function. So on a new line, we'll type two hashtags to format a header for this section, followed by the header text "Setting up my environment." Then we'll add a note about the code. We've added apostrophes before and after "tidyverse" and "palmer penguins" because they're the names of the packages, which makes them part of the actual code. And now we'll add our code. RStudio has a handy code menu that we can use to insert a code chunk. There's also a button in our script pane that lets us add code chunks. This creates a gray section in our file and chunk delimiters. A delimiter is a character that indicates the beginning or end of a data item. You could also type these delimiters directly in the file: three backticks followed by an `r` in braces to begin the code chunk and three backticks to end it. Or you could use the keyboard shortcuts: Control + Alt + I on a PC or Chromebook, and Command + Option + I on a Mac. Since we're in RStudio, the code menu works just fine. Inside the first brace, we'll label our code chunk. After the `r`, we'll add a space and then type "loading packages." This adds another layer to our organization; we can now easily find this code chunk and its label using the contents menu at the bottom of our script pane.

Next, between our delimiters, we'll add our first code chunk, which we use to load our two packages. Even if they're already loaded, loading them again makes sure that our packages will be updated to the latest version. We can type starting on the line after the first delimiter, but since we also have our programming file available, we'll copy and paste from there. Now we can run our code right in the file to check it for errors, and there's the code output. We can also change our code chunk options. There's options for changing the output and for turning off warnings and messages. These are useful for when you're ready to create a final report for stakeholders; you'll have control over what you'll show them in the report. For example, if you get warnings with your output that don't impact your findings, you can turn off the warnings for stakeholders.

Now let's check out this report in its completed form. We'll click the "Knit" button to convert our report to an HTML document. It's got our notes and comments to help us as we keep learning; it's also got code chunks from our previous analysis and output like visuals. So the code chunks are the key to making this report a good learning tool and eventually a document worth presenting to stakeholders. When you have code embedded in a file and can show its output, you can provide evidence for your findings and share your sources. And if you need more evidence for how R Markdown can help you document your analysis, we've got it coming next. See you then!

Hi again. One of the most powerful things about an R Markdown file is that you can convert it to different output types to create shareable reports. We've been focusing on HTML documents, but there are other options we can explore. Let's start by opening our earlier report. We created this report as a learning document to help you think through your code and analysis. For this video, imagine it's a report you need to share with stakeholders. The file is currently in the .Rmd format, but as we've shown, it can be converted using the "Knit" button. The "Knit" drop-down menu includes three main options: HTML, PDF, and a Word document. You can use "Knit" to convert your file to any of these types whenever you want, but it's good practice to wait to convert to a PDF or Word doc. Instead, stick with HTML while you're working. HTML doesn't have page breaks, so you can focus on generating content for your report and not its appearance.

The "Knit" button isn't the only option for converting your file. The YAML can be edited to change your metadata or incorporate more details. For example, we'll change our output in this file to PDF. When we click the "Knit" button to render the file and run the code, the output's in a PDF format. So you know how changing the metadata can have an effect on the whole report. And if you need to create a certain type of document over and over, or if you want to customize the appearance of your final report, you can create a template. If it's a monthly or annual report that you're creating for stakeholders, you can just run one line of code to update your data, and your report's ready. We won't cover creating a template here, but it's something you might want to learn more about on your own as you get more experience in R.

We've now explored a big part of R Markdown and our documentation. We've explained what R Markdown is and how to use it in RStudio to create .Rmd files. We've checked out the structure of these files and how you can format them to make reports. We've shown you what code chunks are and how to include them in your documentation, and we've shown you how to take all of that analysis, plus your explanation of that analysis, and transform it from a .Rmd file into a report that you can use as a learning document or share with stakeholders. It's a great way to wrap up the data analytics process in R and RStudio, and it's nearly time for you to wrap things up in this program. But if you want to review any concepts or practice some more in RStudio, feel free to rewatch the videos anytime for some extra help. See you soon!