Get access to all lessons in this course.
-
Advanced Data Wrangling and Analysis
- Overview
- Importing Data
- Tidy Data
- Reshaping Data
- Dealing with Missing Data
- Changing Variable Types
- Advanced Variable Creation
- Advanced Summarizing
- Binding Data Frames
- Functions
- Merging Data
- Renaming Variables
- Quick Interlude to Reorganize our Code
- Exporting Data
-
Advanced Data Visualization
- Data Visualization Best Practices
- Tidy Data
- Pipe Data Into ggplot
- Reorder Plots to Highlight Findings
- Line Charts
- Use Color to Highlight Findings
- Declutter
- Use the scales Package for Nicely Formatted Values
- Use Direct Labeling
- Use Axis Text Wisely
- Use Titles to Highlight Findings
- Use Color in Titles to Highlight Findings
- Use Annotations to Explain
- Tweak Spacing
- Customize Your Theme
- Customize Your Fonts
- Try New Plot Types
-
Advanced RMarkdown
- Advanced Markdown Text Formatting
- Tables
- Advanced YAML
- Inline R Code
- Making Your Reports Shine: Word Edition
- Making Your Reports Shine: HTML Edition
- Making Your Reports Shine: PDF Edition
- Presentations
- Dashboards
- Other Formats
-
Wrapping Up
- You Did It!
Going Deeper with R
Pipe Data Into ggplot
This lesson is locked
This lesson is called Pipe Data Into ggplot, part of the Going Deeper with R course. This lesson is called Pipe Data Into ggplot, part of the Going Deeper with R course.
Transcript
Click on the transcript to go to that point in the video. Please note that transcripts are auto generated and may contain minor inaccuracies.
Your Turn
Create a new RMarkdown document
Create a data frame called
enrollment_by_race_ethnicity
by reading in your race/ethnicity data from the data wrangling and analysis section using theread_rds()
functionPipe your data into a bar chart that shows the breakdown of race/ethnicity among students in Beaverton SD 48J in 2018-2019
Your chart should look like this:
You need to be signed-in to comment on this post. Login.
Allison Brenner
May 7, 2021
I can't seem to load the rds file and I'm not sure why. The data and RMarkdown file are saved in the Oregon Schools project. Here is my code and error message:
Error in gzfile(file, "rb") : cannot open the connection In addition: Warning message: In gzfile(file, "rb") : cannot open compressed file '/data/enrollment_race_ethnicity.rds', probable reason 'No such file or directory'
Allison Brenner
May 7, 2021
Also - I did load tidyverse package.
David Keyes
May 7, 2021
Try removing the / before data:
enrollment_data <- read_rds("data/enrollment_race_ethnicity.rds")
Let me know if that works!
Atlang Mompe
June 23, 2021
I run this code and get this error message, what am I doing wrong?
Error in filter(., district == "Beaverton SD 48J") : object 'enrollment_by_race_ethnicity' not found
Please advise - I was able to read the rds data and I can see it in the environment pane, but when I use the same code that you shared, I get an error, it says object not found, even though I can see the data on the environment frame.
Atlang Mompe
June 23, 2021
Hi David - please ignore, I had misspelled ethnicity before when reading the rds file, yes I reviewed the code again and I am happy I figured the issue out. Thank you, Atty.
Atlang Mompe
June 23, 2021
Hi David, actually I need your help again, I was able to run the data last night, but I just tried again this morning and this is the error message that I get: Show in New Window Error in gzfile(file, "rb") : cannot open the connection 3. gzfile(file, "rb") 2. readRDS(file) 1. read_rds("data/enrollment-by-race-ethnicity.rds")
So I am not sure what I am doing wrong.
David Keyes
June 23, 2021
This almost certainly means that there isn't a file in the location you're attempting to access one in. Are you sure you spelled everything correctly? Also, are you working in an R script file or RMarkdown? If it's RMarkdown, is your file in the root directory of your project? If it's in a subfolder, that may be causing the issue.
Atlang Mompe
June 23, 2021
Hi David, it turns out I had saved the RMarkdown file in a different folder in my external drive, thank you. It works now.
Mychal Davis
May 18, 2022
Hello,
Which week did we make the RDS file that we are supposed to use for this assignment?
Thank you, Mychal
David Keyes
May 18, 2022
It was in the Exporting Data lesson.
Amy Germuth
November 14, 2022
Hi -
I get the x-y axis (labeled appropriately) but no data plotted......and no error messages.....
Charlie Hadley
November 15, 2022
Hi Amy,
Sorry it's not working. Could you copy and paste your code?
Thanks. Charlie
Kirstin O'Dell
November 21, 2022
I'm having the same issue. I see a graph area with the x and y labels but no bars. Here is the code I'm using enrollment_by_race_ethnicity %>% filter(district == "Beaverton SD 48J") %>% filter(year == "2018-2019") %>% ggplot(aes(x = percent_student_body, y = race_ethnicity)) + geom_col()
David Keyes
November 21, 2022
I believe you need the x variable to be percent_of_total_at_school, not percent_student_body. Let me know if that helps!
Kirstin O'Dell
November 21, 2022
I think that's the same variable. I remember noticing that I had named that one differently than what was in the assignment.
Kirstin O'Dell
November 21, 2022
I tried running just the first filter and got this error message (I only have tidyverse loaded): Error in enrollment_by_race_ethnicity %>% filter(year == "2018-2019") : could not find function "%>%"
Kirstin O'Dell
November 21, 2022
Got the filters to work! I must have done something that required a reload of tidyverse. Still having same issue with the graph not showing though.
Ruimin Xu
May 29, 2023
Hi David, I got blank chart when running below code... Not sure what is wrong enrollment_by_race_ethinicity %>% filter(year=="2018_2019") %>% filter(district=="Beaverton SD 48J") %>% mutate(percent_of_total_at_school=percentage_of_students) %>%
view()
ggplot(aes(x=percent_of_total_at_school,y=race_ethinicity)) geom_col()
David Keyes
May 30, 2023
Can you please post your full code file as a gist and share the link so I can debug?