Get access to all lessons in this course.
-
RMarkdown
- Why Use RMarkdown?
- RMarkdown Overview
- YAML
- Text
- Code Chunks
- Wrapping Up
-
Data Wrangling and Analysis
- Getting Started
- The Tidyverse
- select
- mutate
- filter
- summarize
- group_by
- count
- arrange
- Create a New Data Frame
- Crosstabs
- Wrapping Up
-
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
-
Wrapping Up
- You Did It!
Fundamentals of R
Bar Charts
This lesson is locked
This lesson is called Bar Charts, part of the Fundamentals of R course. This lesson is called Bar Charts, part of the Fundamentals of 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
Complete the bar chart sections of the data-visualization-exercises.Rmd file.
Learn More
Bar Chart Resources
You can also find examples of code to make bar charts on the Data to Viz website , the R Graph Gallery website , and in Chapter 3 of the R Graphics Cookbook. Michael Toth also has a detailed blog post about making bar charts with ggplot.
You need to be signed-in to comment on this post. Login.
Allison Brenner
March 25, 2021
I keep getting an error message "attempt to use zero-length variable name". When I get this it's usually some small thing I missed, but I missed things last week and didn't get this message. I'm wondering why I'm seeing this now, and what exactly it means. Also, suddenly I don't get R Studio's automatic prompts when I begin writing a command. For example, when I start "summarise(" it doesn't prompt with the options for the command. Any ideas why I might be experiencing these changes? I have started a new R session and changed the defaults as you indicated in the lessons, but otherwise haven't made any intentional changes in how I am using R.
David Keyes
March 25, 2021
Hard to say without seeing your code. Could you maybe post a video using Loom or something similar so I can see what's going on and help you?
Nithin Pradeep
October 7, 2021
Hii David, I have a survey dataset with me. The survey has got 4 sections. I want the data to be visualised in such a way that I have "Male" and "Female" in the x-axis and the average sectional scores on y-axis. Can you help me with this?
Nithin Pradeep
October 7, 2021
The visualisation has to be in barchart format.
David Keyes
October 8, 2021
Can you share the data with me? Feel free to email it to me.
Charlie Hadley
October 12, 2021
Hi Nithin, I've recorded a video showing how to do this https://share.getcloudapp.com/geup8QnR and the code is available here https://gist.github.com/charliejhadley/8a410856b69e081531437a5b8c5b83f1
Tatiana Bustos
July 28, 2022
I like the neat fill feature! Thanks for sharing.
Nadia Chang
October 13, 2022
For this exercise I gave the data frame and the new variable the same name, but I got the same result. Why this happened? could this give you any trouble later? But I see it's better to give different names.
Nadia Chang
October 13, 2022
This is the code, the other one wasn't copied right.
Nadia Chang
October 13, 2022
I don't know what happen, but I copy paste the code, but it doesn't appear when I mention nhanes pipe. So I better upload the image: https://imgur.com/a/t9sjubn sleep_by_gender % group_by(gender) %>% summarize(sleep_by_gender = mean(sleep_hrs_night, na.rm = TRUE))
Charlie Hadley
October 13, 2022
Hi Nadia,
There's a typo on the first line of the code, you've got
%
instead of the pipe, which is %>%
Cheers, Charlie
Emma Spielfogel
October 19, 2022
I noticed the code works without putting "mapping=" before aes--is this a bad habit to leave it out? This worked for me:
nhanes %>% ggplot(aes (x=smoke_now)) + geom_bar()
Charlie Hadley
October 19, 2022
Hi Emma,
ggplot() is an example of a function, as is all code that has round brackets. Functions have arguments that have both name and position. The function ggplot() has mapping as the 2nd argument, so we don't need to provide the name of the argument - in fact it's quite rare to actually see code written like ggplot(mapping = aes()).
Cheers, Charlie