Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
paltus
Frequent Visitor

R script visual not working in Service

Hi, 

 

I've created a R visual that load data and makes calendar. Everything is working fine in desktop. 
But in service i get an error: Error in as.POSIXlt.default(x, tz = tz) : do not know how to convert 'x' to class "POSIXlt" 
Date is just a table of dates:

Date
2019-01-01
2019-01-03
2019-01-02
2019-01-04
2019-01-05

 

library(ggplot2)

dfr <- dataset
dfr$day <- factor(strftime(dfr$Date,format="%A"),levels=c("Sunday","Saturday","Friday","Thursday","Wednesday","Tuesday","Monday"))
dfr$week <- factor(strftime(dfr$Date,format="%V"))
dfr$month <- factor(strftime(dfr$Date,format="%B"),levels=c("January","February","March","April","May","June","July","August","September","October","November","December"))
dfr$ddate <- factor(strftime(dfr$Date,format="%d"))

# plot
p <- ggplot(dfr,aes(x=week,y=day))+
geom_text(aes(label=paste(ddate,sep ="
")))+
scale_fill_manual(values=c("#8dd3c7","#ffffb3","#fb8072","#d3d3d3"))+
facet_grid(~month,scales="free",space="free")+
labs(x="Week",y="")+
theme_bw(base_size=12)+
theme(legend.title=element_blank(),
panel.grid=element_blank(),
panel.border=element_blank(),
axis.ticks=element_blank(),
strip.background=element_blank(),
legend.position="top",
legend.justification="right",
legend.direction="horizontal",
legend.key.size=unit(0.4,"cm"),
legend.spacing.x=unit(0.3,"cm"))

plot(p)

 

How can I solve this?

 

Thanks in advance!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @paltus ,

According to error message, it sounds like data format not recognized correctly on power bi service. You can refer to following link to use 'as.Date' or 'as.POSIXlt' functions to convert these date values :

Error in POSIXlt

library(ggplot2)

dfr <- dataset
dfr$day <- factor(strftime(as.POSIXlt(dfr$Date,format = "%Y-%d-%m"),format="%A"),levels=c("Sunday","Saturday","Friday","Thursday","Wednesday","Tuesday","Monday"))
dfr$week <- factor(strftime(as.POSIXlt(dfr$Date,format = "%Y-%d-%m"),format="%V"))
dfr$month <- factor(strftime(as.POSIXlt(dfr$Date,format = "%Y-%d-%m"),format="%B"),levels=c("January","February","March","April","May","June","July","August","September","October","November","December"))
dfr$ddate <- factor(strftime(as.POSIXlt(dfr$Date,format = "%Y-%d-%m"),format="%d"))

# plot
p <- ggplot(dfr,aes(x=week,y=day))+
geom_text(aes(label=paste(ddate,sep ="
")))+
scale_fill_manual(values=c("#8dd3c7","#ffffb3","#fb8072","#d3d3d3"))+
facet_grid(~month,scales="free",space="free")+
labs(x="Week",y="")+
theme_bw(base_size=12)+
theme(legend.title=element_blank(),
panel.grid=element_blank(),
panel.border=element_blank(),
axis.ticks=element_blank(),
strip.background=element_blank(),
legend.position="top",
legend.justification="right",
legend.direction="horizontal",
legend.key.size=unit(0.4,"cm"),
legend.spacing.x=unit(0.3,"cm"))

plot(p)

Regards,

Xiaoxin Sheng

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @paltus ,

According to error message, it sounds like data format not recognized correctly on power bi service. You can refer to following link to use 'as.Date' or 'as.POSIXlt' functions to convert these date values :

Error in POSIXlt

library(ggplot2)

dfr <- dataset
dfr$day <- factor(strftime(as.POSIXlt(dfr$Date,format = "%Y-%d-%m"),format="%A"),levels=c("Sunday","Saturday","Friday","Thursday","Wednesday","Tuesday","Monday"))
dfr$week <- factor(strftime(as.POSIXlt(dfr$Date,format = "%Y-%d-%m"),format="%V"))
dfr$month <- factor(strftime(as.POSIXlt(dfr$Date,format = "%Y-%d-%m"),format="%B"),levels=c("January","February","March","April","May","June","July","August","September","October","November","December"))
dfr$ddate <- factor(strftime(as.POSIXlt(dfr$Date,format = "%Y-%d-%m"),format="%d"))

# plot
p <- ggplot(dfr,aes(x=week,y=day))+
geom_text(aes(label=paste(ddate,sep ="
")))+
scale_fill_manual(values=c("#8dd3c7","#ffffb3","#fb8072","#d3d3d3"))+
facet_grid(~month,scales="free",space="free")+
labs(x="Week",y="")+
theme_bw(base_size=12)+
theme(legend.title=element_blank(),
panel.grid=element_blank(),
panel.border=element_blank(),
axis.ticks=element_blank(),
strip.background=element_blank(),
legend.position="top",
legend.justification="right",
legend.direction="horizontal",
legend.key.size=unit(0.4,"cm"),
legend.spacing.x=unit(0.3,"cm"))

plot(p)

Regards,

Xiaoxin Sheng

Hi, @Anonymous 

 

Thank You for Your advice. 
Everything now works fine, when i use only dates, but when i try to add measure i get an error. 
dataset example:

Data             CR
2019-01-01 50000
2019-01-03 60000
2019-01-02  40000
2019-01-04 30000
2019-01-05 21000


In service i get only Data, not Data + CR



333.JPG
222.JPG

If i write geom_text like this:

geom_text(aes(label=paste(dfr$'CR')
Then i get error: Aesthetics must be either length 1 or the same as the data (13): label, x, y  

 


# dataset <- data.frame(Data, CR)
# dataset <- unique(dataset)
 
Sys.setlocale("LC_TIME""English")
library(ggplot2)


dfr <- dataset
 
 
dfr$day <- factor(strftime(as.POSIXlt(dfr$Data,format = "%Y-%m-%d"),format="%A"),levels=c("Sunday","Saturday","Friday","Thursday","Wednesday","Tuesday","Monday"))
dfr$week <- factor(strftime(as.POSIXlt(dfr$Data,format = "%Y-%m-%d"),format="%V"))
dfr$month <- factor(strftime(as.POSIXlt(dfr$Data,format = "%Y-%m-%d"),format="%B"),levels=c("January","February","March","April","May","June","July","August","September","October","November","December"))
dfr$ddate <- factor(strftime(as.POSIXlt(dfr$Data,format = "%Y-%m-%d"),format="%d"))



dfr$comment <- "Available"

dfr$comment <- factor(dfr$comment,levels=c("Available","Limited","Not available","Weekend"))


# plot
p <- ggplot(dfr,aes(x=week,y=day))+
geom_tile(aes(fill=comment))+
geom_text(aes(label=paste(ddate,dfr$'CR',sep ="
")))+
scale_fill_manual(values=c("#8dd3c7","#ffffb3","#fb8072","#d3d3d3"))+
facet_grid(~month,scales="free",space="free")+
labs(x="Week",y="")+
theme_bw(base_size=12)+
theme(legend.title=element_blank(),
panel.grid=element_blank(),
panel.border=element_blank(),
axis.ticks=element_blank(),
strip.background=element_blank(),
legend.position="top",
legend.justification="right",
legend.direction="horizontal",
legend.key.size=unit(0.4,"cm"),
legend.spacing.x=unit(0.3,"cm"))

plot(p)

 

Can You help me with this problem,please?
Thank You

Anonymous
Not applicable

HI @paltus ,

I'd like to suggest you to refer to following link about geom_lable function:

geom_label

Regards,

Xiaoxin Sheng

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors