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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Kenny_McMillan
Regular Visitor

Change format of Date in Legend in R visual

Hi all,

 

I am trying to solve the following.

 

I have written some R code to make a multiple line graph, and my legend contains the Dates for each line.

 

However, the dates have came out in the following format ...

 

2016-10-11 T00:00:00:00000000

 

How can I force the Date format to 2016-10-11 only ?   I have tried changing the data type in Power BI but to no avail. 

 

Should i be doing this in R and if so, how ?

 

Thanks

R Code is - 

 

library(ggplot2)
dataset$Date <- as.factor(dataset$Date)
ggplot(data = dataset, aes(x = Speed_km.hr, y = LT_test_Lactate, colour = Date, group = Date)) +
geom_point(size = 4) +
theme_classic() +
geom_line(lwd = 2) +
ggtitle("Treadmill assessment - Blood Lactate") +
theme(axis.text.x = element_text( hjust = 1, size=20),
axis.text.y = element_text( hjust = 1, size=18),
axis.title=element_text(size=16, face="bold"),
plot.title = element_text(hjust=0.5, size=18, face="bold"),
legend.position="bottom"
) +
scale_x_continuous(limits = c(11, 18)) +
xlab('Speed') +
ylab("Blood Lactate (mM)") +
geom_hline(yintercept = 4, linetype = "dashed", lwd = 1.3, colour = "grey") 

 

 

 

 

1 ACCEPTED SOLUTION
v-chuncz-msft
Community Support
Community Support

@Kenny_McMillan,

 

You may try using FORMAT Function to add a calculated column.

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-chuncz-msft
Community Support
Community Support

@Kenny_McMillan,

 

You may try using FORMAT Function to add a calculated column.

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you ! @v-chuncz-msft

Anonymous
Not applicable

Greetings, can you please paste the code you have used. I am also trying to implement a dual y-axis chart with one x-axis and different legends. Below would be my ideal requirement

 

col1 acts x-axis

col2 acts y1-axis

col3 acta y2-axis

col4 has some names (name1, name2, name3, name4) the col4 should acts a legend. I know that there is a limitation in power bi, but is there a way I could do this using ggplot. Below is my ideal graph expecting on power bi. 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.