Power BI Scatter Chart and R Scatterplot - a3 b2

Power BI Lissajous Curve Explorer with R

Having finished the ‘Power BI Lissajous Curve Explorer’, I was not 100% happy with the Power BI Scatter Chart visualization.

  1. The data point options are too large for most of the Lissajous Curves and do not look as refined as their equivalents in Excel. This is a minor quibble, but I now realise it was one of the reasons I did not pick up Power BI earlier. Its charts looked too PowerPointy to me. But that was perhaps a function of the dashboards I saw – you know those ones built so that the CXO thinks they are flying an F-14 – it’s all Gauge & Pie Charts up the wazoo.
  2. It would be good to have more control of the data point format. Below, I compare what you see in the Format options for the Scatter Chart, under Shapes – the Size is set to 0% and the Marker Shape set to ‘•’, against what is rendered in the Chart:-

Power BI Scatter Chart Shape and Size

The Marker Shape appears to be an ASCII character whilst the Chart appears to use a Circle Shape that is, at 0% size, twice as big as the ASCII character.

TL;DR: I look at a simple R Scatterplot, how to format it, and compare it to the Power BI Scatter Chart.

Link to .pbix

NOTE: You’ll need Power BI & R installed to view this report.


Where do we go from here?

So, what are the alternatives?

  1. I had a look at other Visualizations, in the Power BI MarketPlace, but didn’t see one that would replace the Scatter Chart.
  2. I could attempt to create my own. For now, this will have to go on the ‘To do’ list.
  3. I could use an R Script Visual.

Option 3 it is then.


Let’s get R eady to R umble!

There is a huge amount of information on R Scatterplots out there and a simple search gave many examples and options. It really took all of 10 mins to get the final R Script Visual working (as long as you’ve already installed R on your PC, of course – otherwise it might take 15 mins).

Add an R Script Visual to your report – the ‘R script editor’ appears at the bottom of your screen asking you to drag fields into the Values area. I simply added x_DAX, y_DAX, and n, from the n Table.

Power BI does some magic in the background to create a dataframe – a virtual table used by R. It also helpfully(?) removes duplicate rows.

You then need to add the R script to plot the Scatter Chart.

That was it. That line above. It produces this:-

Power BI R Script Visual Scatterplot - simple


You can then set the format of the chart.

In this code we:-

  1. Rename the dataset to be just ‘data’ (data <- dataset)
  2. Add x_DAX & y_DAX, as before
  3. Add a colour to the data points (col = “cornflowerblue”)
  4. Define the type of data point to be ‘•’ (pch = 20)
    1. And it is the ASCII character  ‘•’. We know as we can change the pch to be something else. Try pch = “#” or pch = “.”
    2. pch means ‘Plotting Character’, I believe. It actually took me longer to find out what pch meant then it did to format the chart.
    3. A list of pch codes.
  5. Remove the axes (axes = FALSE)
  6. Remove the x & y labels (xlab = NA, ylab = NA)

Which gives us:-

Power BI R Script Visual Scatterplot - clean

Back in Power BI proper, we can add a Title for the R Script Visual and copy across the labels/text we used on the Power BI Scatter Chart.

And comparing the two, side-by-side:-

Power BI Scatter Chart and R Scatterplot - a3 b2Power BI Scatter Chart and R Scatterplot - a40_5 b41Power BI Scatter Chart and R Scatterplot - a74_5 b24_9


Power BI Lissajous Curves Explorer with R: Final Thoughts & Follow-up Posts

  • The combination of Power BI and R works very well.
  • I think I was a bit hard on the Power BI charting engine. Beauty is in the eye of the beholder, so preferences will be different, but for ‘simple’ Lissajous Curves I prefer the R Scatterplot – the lines are cleaner and more refined. However, some of the more ‘complex’ Curves benefit from the circle shape used by Power BI.
  • To be investigated, but I wonder if it is possible to create a Power BI Visualization that does use ASCII characters or gives more control over the shapes used?

Leave a Reply

Your email address will not be published. Required fields are marked *