Thank you for posting! Here is an outline of an effective post:
Describe your issue
- I need help trouble-shooting the ggplot() in the following script.
- This is my second post to the applied epi community as part of my epi-r training
- no urgency
- (No sensitive or identifiable information)
What steps have you already taken to find an answer?
- Searched epi r and analyzed my datasets. Getting all NA in the transformed data
Provide an example of your R code
# install and load packages
pacman::p_load(rio, here, janitor, tidyverse, reprex, datapasta)
# Create a data frame in lieu of import data
#surv_raw <- import(here("data", "raw", "surveillance_linelist_20141201.csv"))
surv_raw <- data.frame(
stringsAsFactors = FALSE,
check.names = FALSE,
`onset date` = c("11/9/2014","10/30/2014",
"8/16/2014","8/29/2014","10/20/2014"),
sex = c("m", "f", "f", "f", "f")
)
# try to convert column to class "Date"
surv_clean <- surv_raw %>%
clean_names() %>%
mutate(onset_date = ymd(onset_date))
#> Warning: There was 1 warning in `mutate()`.
#> ℹ In argument: `onset_date = ymd(onset_date)`.
#> Caused by warning:
#> ! All formats failed to parse. No formats found.
# epicurve
ggplot(data = surv_clean,
mapping = aes(x = onset_date))+
geom_histogram()
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
#> Warning: Removed 5 rows containing non-finite outside the scale range
#> (`stat_bin()`).
# troubleshooting the error
class(surv_clean$onset_date)
#> [1] "Date"
range(surv_clean$onset_date)
#> [1] NA NA
Created on 2025-05-30 with reprex v2.1.1
Session info
sessionInfo()
#> R version 4.5.0 (2025-04-11)
#> Platform: x86_64-apple-darwin20
#> Running under: macOS Sequoia 15.5
#>
#> Matrix products: default
#> BLAS: /Library/Frameworks/R.framework/Versions/4.5-x86_64/Resources/lib/libRblas.0.dylib
#> LAPACK: /Library/Frameworks/R.framework/Versions/4.5-x86_64/Resources/lib/libRlapack.dylib; LAPACK version 3.12.1
#>
#> locale:
#> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#>
#> time zone: America/Los_Angeles
#> tzcode source: internal
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] datapasta_3.1.0 reprex_2.1.1 lubridate_1.9.4 forcats_1.0.0
#> [5] stringr_1.5.1 dplyr_1.1.4 purrr_1.0.4 readr_2.1.5
#> [9] tidyr_1.3.1 tibble_3.2.1 ggplot2_3.5.2 tidyverse_2.0.0
#> [13] janitor_2.2.1 here_1.0.1 rio_1.2.3
#>
#> loaded via a namespace (and not attached):
#> [1] generics_0.1.4 xml2_1.3.8 stringi_1.8.7 hms_1.1.3
#> [5] digest_0.6.37 magrittr_2.0.3 evaluate_1.0.3 grid_4.5.0
#> [9] timechange_0.3.0 RColorBrewer_1.1-3 fastmap_1.2.0 rprojroot_2.0.4
#> [13] scales_1.4.0 cli_3.6.5 rlang_1.1.6 withr_3.0.2
#> [17] yaml_2.3.10 tools_4.5.0 tzdb_0.5.0 pacman_0.5.1
#> [21] curl_6.2.2 vctrs_0.6.5 R6_2.6.1 lifecycle_1.0.4
#> [25] snakecase_0.11.1 fs_1.6.6 pkgconfig_2.0.3 pillar_1.10.2
#> [29] gtable_0.3.6 glue_1.8.0 xfun_0.52 tidyselect_1.2.1
#> [33] rstudioapi_0.17.1 knitr_1.50 farver_2.1.2 htmltools_0.5.8.1
#> [37] rmarkdown_2.29 compiler_4.5.0
Follow-up
- Solved! Thanks ryan.berger for the assist