geom_area plot don't display areas

A strange problem for me. With this dataframe:

df <- data.frame(
  stringsAsFactors = FALSE,
              date = c("01/01/19","01/01/19",
                       "01/01/19","01/02/19","01/02/19","01/02/19","01/03/19",
                       "01/03/19","01/03/19"),
            office = c("Agra","Bondi","Conta",
                       "Agra","Bondi","Conta","Agra","Bondi","Conta"),
             count = c(8211L,1150L,570L,8241L,
                       1140L,587L,8035L,1172L,615L)

I try to make an area chart, with this code:

ggplot(df, aes(x=date, y=count, fill=office)) +
geom_area(size=0.5, alpha=0.8, color='yellow')+
  scale_fill_viridis(discrete = TRUE)+
  theme_ipsum()+
  ggtitle("Customized area plot office sales")

but the result is this:

No areas, no data...
Any ideas?

I think your problem might be that your "date" column is being parsed as a character and not a date. You can use lubridate to fix that. Note - I've used "dmy" because that's the most common way to format data, but if you are an American user (for example) you may need to use "mdy" instead.

library(tidyverse)
df <- data.frame(
  stringsAsFactors = FALSE,
  date = c("01/01/19","01/01/19",
           "01/01/19","01/02/19","01/02/19","01/02/19","01/03/19",
           "01/03/19","01/03/19"),
  office = c("Agra","Bondi","Conta",
             "Agra","Bondi","Conta","Agra","Bondi","Conta"),
  count = c(8211L,1150L,570L,8241L,
            1140L,587L,8035L,1172L,615L))

df %>% 
  mutate(date = lubridate::dmy(date)) %>% 
  ggplot(aes(x=date, y=count, fill=office)) +
  geom_area(size=0.5, alpha=0.8, color='yellow') +
  scale_fill_viridis_d() +
  hrbrthemes::theme_ipsum()+
  ggtitle("Customized area plot office sales")

Created on 2021-12-02 by the reprex package (v2.0.1)

That was the problem, now it works perfectly. Thanks JackDavison.

Regards

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.