Get access to all lessons in this course.
-
Week 1: Getting Started with R
- Welcome to Getting Started with R
- Install R
- Install RStudio
- Projects
- Files in R
- Packages
- Import Data
- Objects and Functions
- Examine our Data
- Import Our Data Again
- Getting Help
- Wrapping Up
- R in 3 Months Spring 2022 Week 1 Live Session
-
Week 2: Fundamentals of R (RMarkdown)
- Welcome to Fundamentals of R
- RMarkdown Overview
- YAML
- Text
- Code Chunks
- Wrapping Up
- R in 3 Months Spring 2022 Week 2 Project Assignment
- R in 3 Months Spring 2022 Week 2 Office Hours
- R in 3 Months Spring 2022 Week 2 Live Session
-
Week 3: Fundamentals of R (Data Wrangling and Analysis)
- Getting Started
- The Tidyverse
- select
- mutate
- filter
- summarize
- group_by
- count
- arrange
- Create a New Data Frame
- Crosstabs
- Wrapping Up
- R in 3 Months Spring 2022 Week 3 Office Hours
- R in 3 Months Spring 2022 Week 3 Live Session
- R in 3 Months Spring 2022 Week 3 Project Assignment
-
Week 4: Fundamentals of R (Data Visualization)
- An Important Workflow Tip
- The Grammar of Graphics
- Scatterplots
- Histograms
- Bar Charts
- color and fill
- scales
- Text and Labels
- Plot Labels
- Themes
- Facets
- Save Plots
- Wrapping Up
- You Did It!
- R in 3 Months Spring 2022 Week 4 Office Hours
- R in 3 Months Spring 2022 Week 4 Live Session
- R in 3 Months Spring 2022 Week 4 Project Assignment
-
Week 5: Catch-Up Week
- R in 3 Months Spring 2022 Week 5 Office Hours
- R in 3 Months Spring 2022 Week 5 Project Assignment: ASSIGNMENT AMNESTY
-
Week 6: Git + GitHub
- What is Git? What is GitHub?
- Why Should You Learn to Use Git and GitHub?
- Update Everything
- Install Git
- Configure Git
- Create a Local Git Repository
- Commits
- Commit History
- GitHub Repositories
- Connect RStudio and GitHub
- Push an RStudio Project to a GitHub Repository
- Pull a GitHub Repository to an RStudio Project
- Keep RStudio and GitHub in Sync
- R in 3 Months Spring 2022 Week 6 Office Hours
- R in 3 Months Spring 2022 Week 6 Live Session
- R in 3 Months Spring 2022 Week 6 Project Assignment
-
Week 7: Going Deeper with R (Advanced Data Wrangling, Part 1)
- Overview
- Importing Data
- Tidy Data
- Reshaping Data
- Dealing with Missing Data
- Changing Variable Types
- Advanced Variable Creation
- Advanced Summarizing
- Binding Data Frames
- R in 3 Months Spring 2022 Week 7 Office Hours
- R in 3 Months Spring 2022 Week 7 Project Assignment
- R in 3 Months Spring 2022 Week 7 Live Session
-
Week 8: Going Deeper with R (Advanced Data Wrangling, Part 2)
- Functions
- Merging Data
- Renaming Variables
- Quick Interlude to Reorganize our Code
- Exporting Data
- R in 3 Months Spring 2022 Week 8 Office Hours
- R in 3 Months Spring 2022 Week 8 Live Session
- R in 3 Months Spring 2022 Week 8 Project Assignment
-
Week 9: Catch-Up Week
- R in 3 Months Spring 2022 Week 9 Office Hours
- R in 3 Months Spring 2022 Week 9 - Assignment Amnesty
-
Week 10: Going Deeper with R (Advanced Data Visualization, Part 1)
- 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
- R in 3 Months Spring 2022 Week 10 Office Hours
- R in 3 Months Spring 2022 Week 10 Live Session
- R in 3 Months Spring 2022 Week 10 Project Assignment
-
Week 11: Going Deeper with R (Advanced Data Visualization, Part 2)
- 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
- R in 3 Months Spring 2022 Week 11 Live Session
- R in 3 Months Spring 2022 Week 11 Office Hours
- R in 3 Months Spring 2022 Week 11 Project Assignment
-
Week 12: Going Deeper with R (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
- You Did It!
- R in 3 Months Spring 2022 Week 12 Office Hours
- R in 3 Months Spring 2022 Week 12 Live Session
- R in 3 Months Spring 2022 Week 12 Project Assignment
-
Week 13: Final Assignment
- R in 3 Months Spring 2022 Week 13 Office Hours
- R in 3 Months Spring 2022 Week 13 Live Session
- R in 3 Months Spring 2022 Final Project Assignment
-
WEEK 14: Retrospective
R in 3 Months (Spring 2022)
Text and Labels
This lesson is locked
This lesson is called Text and Labels, part of the R in 3 Months (Spring 2022) course. This lesson is called Text and Labels, part of the R in 3 Months (Spring 2022) course.
If the video is not playing correctly, you can watch it in a new window
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
Complete the text and labels sections of the data-visualization-exercises.Rmd file.
Learn More
text and labels Resources
Data Visualization: A Practical Introduction has a section in Chapter 5 on adding text to plots, as does Chapter 28 of R for Data Science.
Information about using vjust and hjust is on the geom_label page of the tidyverse website.
Also, check out the ggrepel package , which automatically adjusts overlapping text and labels.
You need to be signed-in to comment on this post. Login.
Catherine Roller White
April 10, 2021
When I rounded the value labels for average number of hours of sleep, they displayed as 7 and 6.9. I like to keep the number of decimals displayed consistent, even if the decimal is equal to zero. How can I round to one decimal but have 7.0 display as 7.0 instead of 7? Thank you.
Megan Ruxton
April 14, 2021
If I have a bar chart with a frequency on the y axis, how do I apply the geom_text and geom_label? For example, in my project I begin with the following code: ggplot(data = intro_etc, aes(x = gender_identity, fill = gender_identity))+ geom_bar() So there isn't anything listed for the y axis for me to enter into the command for geom_text or geom_label.
Lisa Janz
May 11, 2021
The colour of the text keeps turning up red rather than white. I have tried with other colours, but none of them work. I also tried ordering the code the way that it was done in the solutions. Any suggestions as to why this is happening? Is there a library that I haven't loaded? I will also note that in the legend there is a spot for "colour", so it looks like the program has coded colour as a variable. ggplot(sleep_by_gender, mapping = aes(x = gender, y = avg_sleep, fill = gender)) + geom_col() + scale_fill_manual(values = c("yellow", "orange"))+scale_y_continuous(breaks = c(seq(from = 0, to = 8, by = 1))) + geom_text (aes(label = round(avg_sleep, 1), vjust = 1.5, colour = "white"))
Lisa Janz
May 11, 2021
To position the labels in this exercise, you use vjust = -1.1
Negative and positive values were not discussed in the video and if I use -1.1, the label disappears from the graph. Can you clarify? Is this just a mistake in the tutorial or is my graph too small. What do the numbers represent? Are they related to the width of bins?
Matt M
October 10, 2021
Will there be any tutorials on how to use Help files? I've yet to successfully use one. I entered ?geom_text into the console and got to the help file but have no idea where I'm supposed to put the relevant code and not confident that I know how to parse what it's telling me. For this specific task, I added :show.legend = FALSE: to the very end of my code, but that just removed an "a" within the label. How was I supposed to know from only reading the Help file that I needed put it in 2 places?
sleep_by_gender% mutate(avg_sleep = round(avg_sleep, 1)) ggplot(data=sleep_by_gender, mapping=aes(x=gender, y=avg_sleep, fill=gender))+ geom_col()+ scale_color_brewer(type = "div", palette = "PuOr")+ scale_y_continuous(limits = c(0, 8), breaks = c(0, 1, 2, 4, 6, 8))+ geom_label(aes(label=avg_sleep), vjust= -.5, color= "white", show.legend = FALSE)
Jay Cutler
March 4, 2022
Hi David, with your code here...
geom_text(aes(label = round(avg_sleep, 1)), vjust = 1.5, color = "white")
My intuitive way of typing the code was to include the 'vjust' and 'color' arguments within the aesthetics parenthetical, like so:
geom_text(aes(label = round(avg_sleep, 1), vjust = 1.5, color = "white"))
...which largely worked, but my text was a strange pink color instead of white. I'm curious why this is the case? Any rhyme or reason to distinguish between what arguments end up with the 'label' piece in the aesthetics parenthetical and what arguments live freely in the geom_text function? Thanks!
Zaynaib Giwa
April 1, 2022
Hello everyone, For some reason, I can't get the text to turn white. Hopefully, I can get a second pair of eyes on my code. It changes the color to the fill color of female.
ggplot(sleep_by_gender, aes(x=gender, y=avg_sleep, fill=gender)) + geom_col() + scale_y_continuous(limits=c(0,8), breaks = c(0,1,2,3,4,5,6,7,8)) + geom_text(aes(label = round(avg_sleep,1), vjust = 1, color = "white"
Jordan Helms
April 7, 2022
Why do we have to turn the legend off in two places?
Arne Floh
April 13, 2022
Why have you added the following code line: na.value = "blue"
Niger Sultana
May 25, 2022
Hi I wanted to add superscript, subscript as label on x axis through ggtext package? for example, WD (mg mm-3), -3 will be superscript in R script and Markdown file? or will this work : geom_text(aes(label = paste(WD, (mg)"^(",-3 , ")", sep = "")), parse = TRUE)
Thanks in advance.
Kirstin O'Dell
October 19, 2022
To turn the legend off I used theme (legend.position = "none") and it worked. I wondered if there was a difference between using that code and the way you showed it?