Use Direct Labeling
This lesson is called Use Direct Labeling, part of the R in 3 Months (Fall 2021) course. This lesson is called Use Direct Labeling, part of the R in 3 Months (Fall 2021) 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
Add text to display the percentage of Hispanic/Latino students in Douglas ESD in 2017-2018 and 2018-2019.
You’ll want to use case_when()
and str_glue()
. If you want some guidance with str_glue()
, check out its help page. When using this function, put everything you want to glue together in quotes, with curly brackets around variables.
Have any questions? Put them below and we will help you out!
Course Content
134 Lessons
1
Welcome to Getting Started with R
00:57
2
Install R
02:05
3
Install RStudio
02:14
4
Projects
07:54
5
Files in R
04:33
6
Packages
02:38
7
Import Data
05:24
8
Objects and Functions
03:16
9
Examine our Data
12:50
10
Import Our Data Again
07:11
11
Getting Help
07:46
12
Wrapping Up
13
R in 3 Months Fall 2021 Week 1 Live Session
54:07
1
Getting Started
03:01
2
The Tidyverse
12:11
3
select
05:48
4
mutate
04:08
5
filter
10:26
6
summarize
03:20
7
group_by
02:56
8
count
02:06
9
arrange
03:58
10
Create a New Data Frame
02:42
11
Crosstabs
06:58
12
Wrapping Up
13
R in 3 Months Fall 2021 Week 3 Project Assignment
06:03
14
R in 3 Months Fall 2021 Week 3 Office Hours
55:49
15
R in 3 Months Fall 2021 Week 3 Live Session
1:10:01
1
An Important Workflow Tip
05:00
2
The Grammar of Graphics
06:08
3
Scatterplots
05:15
4
Histograms
02:31
5
Bar Charts
06:32
6
color and fill
03:58
7
scales
09:14
8
Text and Labels
08:04
9
Plot Labels
06:06
10
Themes
03:56
11
Facets
05:57
12
Save Plots
05:17
13
Wrapping Up
14
You Did It!
15
R in 3 Months Fall 2021 Week 4 Project Assignment
04:40
16
R in 3 Months Week 4 Office Hours
56:30
17
R in 3 Months Fall 2021 Week 4 Live Session
1:05:25
1
What is Git? What is GitHub?
02:23
2
Why Should You Learn to Use Git and GitHub?
03:04
3
Update Everything
07:34
4
Install Git
04:04
5
Configure Git
02:10
6
Create a Local Git Repository
03:16
7
Commits
06:00
8
Commit History
04:28
9
GitHub Repositories
04:47
10
Connect RStudio and GitHub
05:06
11
Push an RStudio Project to a GitHub Repository
02:57
12
Pull a GitHub Repository to an RStudio Project
02:52
13
Keep RStudio and GitHub in Sync
02:27
14
R in 3 Months Week 6 Office Hours
59:43
15
R in 3 Months Fall 2021 Week 6 Project Assignment
07:55
16
R in 3 Months Fall 2021 Week 6 Live Session
54:10
1
Overview
2
Importing Data
15:45
3
Tidy Data
08:11
4
Reshaping Data
10:18
5
Dealing with Missing Data
04:56
6
Changing Variable Types
05:30
7
Advanced Variable Creation
19:26
8
Advanced Summarizing
10:00
9
Binding Data Frames
06:50
10
R in 3 Months Fall 2021 Week 7 Project Assignment
06:14
11
R in 3 Months Fall 2021 Week 7 Live Session
51:31
12
R in 3 Months Week 7 Office Hours
35:07
1
Data Visualization Best Practices
04:51
2
Tidy Data
04:01
3
Pipe Data Into ggplot
04:50
4
Reorder Plots to Highlight Findings
06:09
5
Line Charts
04:10
6
Use Color to Highlight Findings
08:25
7
Declutter
10:47
8
Use the scales Package for Nicely Formatted Values
03:42
9
Use Direct Labeling
11:43
10
R in 3 Months Fall 2021 Week 10 Project Assignment
04:47
11
R in 3 Months Week 10 Office Hours
52:28
12
R in 3 Months Fall 2021 Week 10 Live Session
1:13:30
1
Use Axis Text Wisely
03:15
2
Use Titles to Highlight Findings
03:33
3
Use Color in Titles to Highlight Findings
03:51
4
Use Annotations to Explain
04:52
5
Tweak Spacing
05:11
6
Customize Your Theme
02:48
7
Customize Your Fonts
08:18
8
Try New Plot Types
11:50
9
R in 3 Months Fall 2021 Week 11 Project Assignment
10
R in 3 Months Week 11 Office Hours
1:07:41
11
R in 3 Months Fall 2021 Week 11 Live Session
48:31
1
Advanced Markdown Text Formatting
10:52
2
Tables
19:33
3
Advanced YAML
11:49
4
Inline R Code
06:57
5
Making Your Reports Shine: Word Edition
06:53
6
Making Your Reports Shine: HTML Edition
06:32
7
Making Your Reports Shine: PDF Edition
08:21
8
Presentations
04:21
9
Dashboards
06:28
10
Other Formats
04:57
11
You Did It!
12
R in 3 Months Week 12 Project Assignment
08:22
13
R in 3 Months Week 12 Office Hours
54:19
14
R in 3 Months Week 12 Live Session
59:42
You need to be signed-in to comment on this post. Login.
Vuk Sekicki • May 13, 2021
Hello David, This works well if we use one line as you said. However I was experimenting with top 3 schools. It actually does not move middle one for whatever reason. Let me share the code:
highlight_district % filter(race_ethnicity == "Hispanic/Latino") %>% filter(district == "Douglas ESD" | district == "Troy SD 54" | district == "InterMountain ESD") %>% mutate(percent_display = percent(percentage, accuracy = 1)) %>% mutate(percent_display = case_when( year == "2018_2019" ~ str_glue("{percent_display} of students"), TRUE ~ percent_display ))
total_enrolement %>% filter(race_ethnicity == "Hispanic/Latino") %>% ggplot(aes(x= year, y= percentage, group = district)) + geom_line(color = "light gray") + geom_line(data = highlight_district, aes(x= year, y= percentage, group = district, color = district)) + theme_minimal() + geom_text(data = highlight_district, inherit.aes = TRUE, aes(label = percent_display), nudge_x = c(-0.1,0.1) )
Harold Stanislaw • May 20, 2021
I experimented with fig.width to prevent my label from getting truncated. This displayed the entire line, but it also rescaled the text so it became quite small and was no longer directly adjacent to the line it was labeling. I tried using ggfittext to wrap the text, but couldn't get it to work :(
Juan Clavijo • December 1, 2021
Hello, you mentioned in the live session a package to help put graphs together, next to one another in the layout. Could you please re-share that here?
David Keyes Founder • December 8, 2021
I'm not quite sure I follow your question. Can you expand a bit please?
Tarisirai Zengeni • December 23, 2021
Hi Davi,
I have been stuck for weeks now on getting this code to work.
highlight_district% filter(race_ethnicity=="Hispanic/Latino") %>% filter(district=="Douglas ESD")%>% mutate(percent_display = percent(percent_of_total_at_school, accuracy = 1))%>% mutate(percent_display = case_when( year=="2018-2019" ~ str_glue("{percent_display} Latino students"), TRUE ~ percent_display ))
I keep getting the error message:
Error: Problem with
mutate()
columnpercent_display
. ipercent_display = case_when(...)
. x unused argument (accuracy = 1) Runrlang::last_error()
to see where the error occurred.I even tried reinstalling the R suite and no change. When I try to open the highlight_district dataframe to view, I also get an error message (r error 4 (R code execution error)) with the option to retry which doesnt work - i get the same r error 4 message. i even tried starting a new markdown file but still same result. Counsel says:
Error in formatC(c(0, 13.6363636363636), format = "f", digits = 2L, accuracy = 1) : unused argument (accuracy = 1)
I am at a loss.
Hatem Kotb • January 15, 2023
For some reason this code throws an error, but when I switch the order of the lines in the case_when it doesn't 🙄
Code: enrollment_by_race_ethnicity % mutate(percent_display = percent(percentage, accuracy = 1)) %>% mutate(percent_display = case_when( year == "2017" ~ percent_display, year == "2018" ~ str_glue("{percent_display} Latino students")))
Error: Error in
mutate()
: ! Problem while computingpercent_display = case_when(...)
. Caused by error incase_when()
:Backtrace: