0

I am trying to create a specific gg stacked barplot with specific x axis values

 `ggplot(SIARC_Org_Adj, aes(fill=fct_relevel(ID_Confidence,"2", "3", "4", "5"), y=No_Individuals, x= fct_relevel(Year_Range, "1812", "1858","1870","1874" ,"1875", "1878","1893", "1897", "1899", "1903", "1905", "1908", "1918","1923","1934", "1938", "1939", "1953", "1958", "1960", "1970", "1974", "1977", "1978", "1979", "1980", "1982", "1983", "1984", "1985", "1986", "1987", "1989", "1990",      "1992", "1993", "1999", "2000", "2002", "2003", "2004", "2009", "2010", "2011", "2013", "2014",      "2015", "2016", "2017", "2018", "2019", "2020", "2021", "2022" ))) + 
geom_bar(position="stack",stat="identity")+
  scale_fill_manual(values =c( "2"= "grey80",
                         "3" = "grey73",
                         "4"= "grey50",
                         "5"= "grey30"))+
 xlab("Month")+ ylab("Number of S. squatina")+
 labs(fill= "Sex")`

I get the followqing error

 `Warning: Ignoring unknown parameters: `stat`Error in `geom_bar()`:

! Problem while computing aesthetics. ℹ Error occurred in the 1st layer. Caused by error: ! f must be a factor (or character vector). Backtrace:

  1. base (local) <fn>(x)
  2. forcats::fct_relevel(...)
  3. forcats:::check_factor(.f)
  4. base::stop("f must be a factor (or character vector).", call. = FALSE) Error in geom_bar(position = "stack", stat = "identity") : ℹ Error occurred in the 1st layer. Caused by error: ! f must be a factor (or character vector).`
stefan
  • 90,330
  • 6
  • 25
  • 51
  • Welcome to SO! To help us to help you would you mind sharing [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including a snippet of your data or some fake data. To share your data, run e.g. `dput(head(NAME_OF_DATASET, 10))` and copy the output into your post. – stefan Jun 21 '23 at 21:23

0 Answers0