Ggplot(data = surv_clean,mapping = aes) error

Thank you for posting! Here is an outline of an effective post:

Describe your issue

  • What specifically do you need help with
  • Relevant context (e.g. public health trends or associated data infrastructure)
  • Timeline/urgency
  • (No sensitive or identifiable information)

What steps have you already taken to find an answer?

Provide an example of your R code

  • Watch this video: https://www.youtube.com/watch?v=XIc-VHFeUl8
    This document is also helpful: Reprex do's and don'ts • reprex

  • If pasting your code, put it in backticks so that others can easy copy/paste:

    • Use single backticks to make text appear as code, like mutate() and filter()
    • Use 3 backticks on lines above and below a large block of text to make it appear as code
    male_cases <- linelist %>%
       filter(gender == "male")
    

Follow-up

  • Thank the volunteers who try to help you
  • Mark one reply as the “Solution” if appropriate
pacman::p_load(rio, here, janitor, tidyverse, reprex, datapasta)

surv_raw <- data.frame(
  stringsAsFactors = FALSE,
  check.names = FALSE,
  case_id = c("694928", "86340d", "92d002", "544bd1", "6056ba"),
  sex = c("m", "f", "f", "f", "f"),
  `onset date` = c("11/9/2014","10/30/2014",
                   "8/16/2014","8/29/2014","10/20/2014"))
surv_clean <- surv_raw %>% 
  clean_names() %>% 
  mutate(onset_date = mdy(onset_date))
ggplot(data = surv_clean,mapping = aes(
  x = onset_date)) + geom_histogram())
#> Error in parse(text = input): <text>:14:38: unexpected ')'
#> 13: ggplot(data = surv_clean,mapping = aes(
#> 14:   x = onset_date)) + geom_histogram())
#>                                          ^

Hello,

The format of your date variable is mm/dd/YYY but you use the ymd function. Instead, use the mdy function which will work with your data.

Regards,

Tim