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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
beaverbuzz85
Regular Visitor

Problem Creating Box plot with R (wrong mean and median)

Good morning!

 

I am encountering some issues while trying to create a box plot with R. 

The plot loads on the screen, i..e no problems with libraries; however, the mean and median are completely wrong.

 

beaverbuzz85_0-1685547944104.png

beaverbuzz85_0-1685549296238.png

 

For the far left box, the mean is supposed to be 4.3, yet, as you can see it is closer to 50.

 

I believe the problem lies with R determining how to calculate mean and median with the raw data. Although, it appears the dots on the box plot are correct, i.e. they correspond with the numbers in the raw data.

For clarity, the raw data contains about 200,000 rows and each row contains a number (IND_CASE_COUNT) and a category (PCTY_CD). 

 

Any help on this would be appreciated. I ran into a similar problem with one of the downloadable visuals, as it produced a box plot but it was not producing the correct mean and median. 


Thank you 🙂

 

2 REPLIES 2
beaverbuzz85
Regular Visitor

I am not sure if we are allowed to bump messages. I would appreciate some help, even if it means posting this in a different forum. Thanks!

FYI boxplots do not display means! The lines in the boxplots you posted are the medians of each group and each box stretches between the 1st and 3rd quartiles of your data. So, first thing I'd suggest is checking if some medians you calculate in your data are matching up with the boxplots. If you're finding the box plots are still not lining up with your expectations, the only Power BI element I could see contributing to the issue is if you're summarizing the fields you added to the visual or something. You could also just build the plot in R (outside of PBI) and see if they are the same to confirm whether PBI is affecting the output.

 

Hope this helps!

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Fabric Monthly Update - May 2024

Check out the May 2024 Fabric update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.