Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredGet Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
Hi All,
I am using R code to generate a scatter plot with moving average but when I run the code I am getting the below error.
library(ggplot2)
library(zoo, warn.conflicts = FALSE)
library(dplyr, warn.conflicts = FALSE)
library(lubridate, warn.conflicts = FALSE)
dataset$Date_of_Cleaning__c = as.factor(dataset$Date_of_Cleaning__c)
dataset$Date_of_Cleaning__c = as.Date(dataset$Date_of_Cleaning__c,format="%d/%m/%Y")
# find moving average
zoo.avg <- zoo(dataset$Specific_Water_Usage__c)
ma1 <- rollapplyr(zoo.avg, 2, mean, fill = NA, na.rm = T)
#result$avgwu=coredata(ma1)
#plot graph
p <- ggplot(data=dataset, aes(x= Date_of_Cleaning__c, y= Specific_Water_Usage__c, color= Name))+
ylab("Water Usage") + geom_point()+
ggtitle(paste0("Water Management")) +
scale_x_date(date_breaks = "1 month",date_labels = "%b/%y")+
theme(axis.title.y = element_text(size = 11, face = "bold",margin = margin(0,2,0,0)))+
theme(axis.title.x = element_text(size = 11, face = "bold"))+
theme(axis.text.x = element_text(size=11))+
theme(axis.text.y = element_text(size=11))+
theme(plot.title = element_text(face = "bold",size= 11,lineheight = 0.7,hjust = 0.5), plot.subtitle = element_text(face = "bold",size= 12,lineheight = 0.9,hjust = 0.5))+
theme(plot.title=element_text(margin=margin(0,0,7,0)))+
#geom_smooth(data=result, aes(x=Date, y=avgwu),color="red", size=1.5,se=FALSE)
It seems that you may remove the last plus sign (+).
HI @v-chuncz-msft,
I had removed the (+), another issue is I was using ggplot to plot geom_point(), however, the date is overlapped each other.
So try to use scale_x_date(date_breaks = "1 month",date_labels = "%b/%y"), however is not working due to the date format.
#date format
dataset$Date_of_Cleaning__c = as.factor(dataset$Date_of_Cleaning__c)
dataset$Date_of_Cleaning__c = as.Date(dataset$Date_of_Cleaning__c,format="%d/%m/%Y")
I did change the date format using the code above, it shows error in seq.int(0, to0 - from, by)...
Anyone can help me to solve this issue?
is there any way to overcome the date overlapping each other?
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
Check out the October 2025 Power BI update to learn about new features.