My first training post- error in ggplt bar plot

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

# reprex1 script

# 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

# create a minimal dataset of 5 rows and 2 columns
#surv_raw %>% 
#  head(5) %>%                      # for the top 5 rows
# select(adm3_name_res,sex) %>%    # select 2 columns
#  dpasta()                        # convert to stand alone R code

Created on 2025-05-13 with reprex v2.1.1

Session info
sessioninfo::session_info()
#> Warning in system2("quarto", "-V", stdout = TRUE, env = paste0("TMPDIR=", :
#> running command '"quarto"
#> TMPDIR=C:/Users/HP/AppData/Local/Temp/Rtmpyuczvl/filef2065527957 -V' had status
#> 1
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.4.1 (2024-06-14 ucrt)
#>  os       Windows 11 x64 (build 22000)
#>  system   x86_64, mingw32
#>  ui       RTerm
#>  language (EN)
#>  collate  English_United States.utf8
#>  ctype    English_United States.utf8
#>  tz       Africa/Lagos
#>  date     2025-05-13
#>  pandoc   3.2 @ C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown)
#>  quarto   NA @ C:\\PROGRA~1\\RStudio\\RESOUR~1\\app\\bin\\quarto\\bin\\quarto.exe
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date (UTC) lib source
#>  cli           3.6.4   2025-02-13 [1] CRAN (R 4.4.2)
#>  colorspace    2.1-1   2024-07-26 [1] CRAN (R 4.4.2)
#>  datapasta   * 3.1.0   2020-01-17 [1] CRAN (R 4.4.3)
#>  digest        0.6.37  2024-08-19 [1] CRAN (R 4.4.2)
#>  dplyr       * 1.1.4   2023-11-17 [1] CRAN (R 4.4.2)
#>  evaluate      1.0.3   2025-01-10 [1] CRAN (R 4.4.2)
#>  fastmap       1.2.0   2024-05-15 [1] CRAN (R 4.4.2)
#>  forcats     * 1.0.0   2023-01-29 [1] CRAN (R 4.4.2)
#>  fs            1.6.5   2024-10-30 [1] CRAN (R 4.4.2)
#>  generics      0.1.3   2022-07-05 [1] CRAN (R 4.4.2)
#>  ggplot2     * 3.5.1   2024-04-23 [1] CRAN (R 4.4.2)
#>  glue          1.8.0   2024-09-30 [1] CRAN (R 4.4.2)
#>  gtable        0.3.6   2024-10-25 [1] CRAN (R 4.4.2)
#>  here        * 1.0.1   2020-12-13 [1] CRAN (R 4.4.3)
#>  hms           1.1.3   2023-03-21 [1] CRAN (R 4.4.2)
#>  htmltools     0.5.8.1 2024-04-04 [1] CRAN (R 4.4.2)
#>  janitor     * 2.2.1   2024-12-22 [1] CRAN (R 4.4.3)
#>  knitr         1.49    2024-11-08 [1] CRAN (R 4.4.2)
#>  lifecycle     1.0.4   2023-11-07 [1] CRAN (R 4.4.2)
#>  lubridate   * 1.9.4   2024-12-08 [1] CRAN (R 4.4.2)
#>  magrittr      2.0.3   2022-03-30 [1] CRAN (R 4.4.2)
#>  munsell       0.5.1   2024-04-01 [1] CRAN (R 4.4.2)
#>  pacman        0.5.1   2019-03-11 [1] CRAN (R 4.4.3)
#>  pillar        1.10.1  2025-01-07 [1] CRAN (R 4.4.2)
#>  pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.4.2)
#>  purrr       * 1.0.4   2025-02-05 [1] CRAN (R 4.4.2)
#>  R6            2.6.1   2025-02-15 [1] CRAN (R 4.4.2)
#>  readr       * 2.1.5   2024-01-10 [1] CRAN (R 4.4.2)
#>  reprex      * 2.1.1   2024-07-06 [1] CRAN (R 4.4.2)
#>  rio         * 1.2.3   2024-09-25 [1] CRAN (R 4.4.3)
#>  rlang         1.1.5   2025-01-17 [1] CRAN (R 4.4.2)
#>  rmarkdown     2.29    2024-11-04 [1] CRAN (R 4.4.2)
#>  rprojroot     2.0.4   2023-11-05 [1] CRAN (R 4.4.3)
#>  rstudioapi    0.17.1  2024-10-22 [1] CRAN (R 4.4.2)
#>  scales        1.3.0   2023-11-28 [1] CRAN (R 4.4.2)
#>  sessioninfo   1.2.3   2025-02-05 [1] CRAN (R 4.4.3)
#>  snakecase     0.11.1  2023-08-27 [1] CRAN (R 4.4.3)
#>  stringi       1.8.4   2024-05-06 [1] CRAN (R 4.4.0)
#>  stringr     * 1.5.1   2023-11-14 [1] CRAN (R 4.4.2)
#>  tibble      * 3.2.1   2023-03-20 [1] CRAN (R 4.4.2)
#>  tidyr       * 1.3.1   2024-01-24 [1] CRAN (R 4.4.2)
#>  tidyselect    1.2.1   2024-03-11 [1] CRAN (R 4.4.2)
#>  tidyverse   * 2.0.0   2023-02-22 [1] CRAN (R 4.4.2)
#>  timechange    0.3.0   2024-01-18 [1] CRAN (R 4.4.2)
#>  tzdb          0.4.0   2023-05-12 [1] CRAN (R 4.4.2)
#>  vctrs         0.6.5   2023-12-01 [1] CRAN (R 4.4.2)
#>  withr         3.0.2   2024-10-28 [1] CRAN (R 4.4.2)
#>  xfun          0.52    2025-04-02 [1] CRAN (R 4.4.3)
#>  yaml          2.3.10  2024-07-26 [1] CRAN (R 4.4.2)
#> 
#>  [1] C:/Users/HP/AppData/Local/R/win-library/4.4
#>  [2] C:/Program Files/R/R-4.4.1/library
#>  * ── Packages attached to the search path.
#> 
#> ──────────────────────────────────────────────────────────────────────────────

Hello @frank007:

I think you have to write surv_clean (whitout the capital S) inside the ggplot command, to match the name of the object you created a few lines above.

Best regards.

Hello,
Thank you very much for helping out.