0
votes

This is my previous data

Jan_df=Jan %>%
 
select("Updated_Date","Amount") %>% 
 
mutate(Date=parse_date_time(Jan$Updated_Date,"ymd_HMS",tz="")) %>% 
  
select(Date,Amount) %>% 
  
group_by(date(Date)) %>% 
  
summarise(sale_per_day=sum(Amount))

[This the data after I grouped by dates followed by summarize sales per day][2]

library(ggplot2)

ggplot(Jan_df,aes(x=(date(Date)),y=sale_per_day,fill=sale_per_day))+
  
geom_bar(satat="identity")

I got error while running above code for plotting bar plot for sales w.r.t to date

**> ggplot(Jan_df,aes(x=(date(Date)),y=sale_per_day,fill=sale_per_day))+

  • geom_bar(satat="identity")

Error in as.POSIXlt.default(x, tz = tz(x)) :

do not know how to convert 'x' to class “POSIXlt”

In addition: Warning message:

Ignoring unknown parameters: satat**

1
You have a typo in stat = 'identity'. Also, can you try using as.Date(Date) instead of date(Date)?Elle
Thank you Yes I have tried by using as.Data but get the error like below Error in as.Date.default(Date) : do not know how to convert 'Date' to class “Date” already Date variable is in "POSIXct" "POSIXt" type see below for your reference class(Jan_df[,3]) [1] "POSIXct" "POSIXt"Amara Siva Teja
So is it already a Date?Elle
Yes i have converted it by using below code Date=parse_date_time(Jan$Updated_Date,"ymd_HMS",tz="")Amara Siva Teja
So why are you converting it again?Elle

1 Answers

0
votes

aes is not recognizing the column name you had given - date(Date). try changing the column names Also, as Elle pointed out you need change the parameter name from 'satat' to 'stat'

code:

colnames(Jan_df) = c("Day","Sales")

library(ggplot2)

ggplot(Jan_df,aes(x= Day,y=Sales,fill=Sales))+

geom_bar(stat="identity")

Full code for reference:

##Data Jan = data.frame(Updated_Date=c('2021-01-01 11:00:05','2021-01-01 12:00:16','2021-01-02 14:02:09','2021-01-04 21:30:38'),Amount=c(1000,2000,3000,4000))

##libraries library(dplyr) library(lubridate)

###Summarization of Sales by date

Jan_df=Jan %>%

select("Updated_Date","Amount") %>%

mutate(Date=parse_date_time(Jan$Updated_Date,"ymd_HMS",tz="")) %>%

select(Date,Amount) %>%

group_by(date(Date)) %>%

summarise(sale_per_day=sum(Amount))

##changing column names

colnames(Jan_df) <- c('Day','Sales')

Bar plot

library(ggplot2)

ggplot(Jan_df,aes(x= Day,y=Sales,fill=Sales))+

geom_bar(stat="identity")