My first training post - error in barplot *** (training)

Hello, I tried to solve this but can not figure it out. Below is a reprex of my problem. I am expecting a ggplot bar plot but I’m getting an error saying the data is not found.
Thank you in advance for helping me!

#######################
# Example - Forum Post       
#######################
# install and load packages
pacman::p_load(rio, here, janitor, tidyverse, reprex, datapasta)

# import data
surv_raw <- data.frame(
  stringsAsFactors = FALSE,
  adm3_name_res = c(NA,"Mountain Rural",
                    "Mountain Rural","East II","West III"),
  sex = c("m", "f", "f", "f", "f")
)

# clean the surveillance data
surv_clean <- surv_raw %>% 
  clean_names()

# make a horizontal bar plot of cases per district, filled by sex
ggplot(
  data = Surv_clean,
  mapping = aes(y = adm3_name_res, fill = sex))+
  geom_bar()
#> Error: object 'Surv_clean' not found

Created on 2025-06-30 with reprex v2.1.1

Session info


Hello,

R is case sensitive so surv_clean and Surv_clean to do not refer to the same object in the environment. Rather, these are two different objects, the latter of which was never defined. Replacing Surv_clean with surv_clean in the ggplot function will solve this issue.

All the best,

Tim

1 Like