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
prateekraina
Memorable Member
Memorable Member

Need help in R Visual

Hi Everyone,

 

I am in process of creatiing a R Visual in which i need to change color of line above threshold.
So far, i have written below script to genrate the visual uploaded below. Can someone help me to get my desired result i.e If my threshold is breahed/surpassed, color of line should change.

If this can be achived using traditional Power BI visuals then that suggestion is also welcome.
Here is my code and visual created so far.

plot(dataset$Temperature,type="l",lwd=2,
xaxt="n",col="blue",
xlab="Date",ylab="Temperature",
main="Demo Chart")
axis(1,at=1:length(dataset$Date),labels=dataset$Date)
abline(h=dataset$TargetTemperature,col="red")

Solution1.PNGSolution2.PNG

Edit 1: Sorry for tagging you guys. Kindly help if anybody knows.


@Greg_Deckler

@MarcelBeug

@Vvelarde

@Phil_Seamark

@MFelix

@v-haibl-msft
@v-huizhn-msft
@Seth_C_Bauer

1 ACCEPTED SOLUTION

Try below R code. Multiple colours works for points i.e. col = ifelse(temperature >15,"blue","red") etc  but does not work for line charts in base R plot.

 

plot(dataset$Temperature,type = "l",col = "blue")
abline(h=10,col = "red")
clip(0,100,0,10)
lines(dataset$Temperature, col='green', type='l')

 

View solution in original post

10 REPLIES 10

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.