Alteryx designer Discussions

Find answers, ask questions, and share expertise about Alteryx Designer.
SOLVED

Configuring the R Tool for charting

Asteroid

Hi,

 

Apologies for asking but I was hoping that someone here might have already used the R Tool for producing charts and might show me how it is done.  I have attached an example but don't seem to be able to reproduce the inbuilt Charting tools output.  I am hoping that once I can see it in action that I will be able to move on myself.

 

Many thanks in advance,

Peter

Highlighted
ACE Emeritus
ACE Emeritus

I'm not sure if the following will work for your needs, but the "pie" command in R will generate a pie chart in fairly straight-forward fashion.

 

For more info on that, see here: https://www.tutorialspoint.com/r/r_pie_charts.htm

Plotly is becoming popular now also: https://plot.ly/r/pie-charts/

 

For simplicity, I focus on the first option, rather than plotly, in the attached workflow.  The workflow uses a BlockUntilDone tool to run the R script which stores the chart as a .png; then the next step grabs the PNG and renders the image, similar to what you had in your stream. (But if the .PNG suits your needs, then you could just run straight into the R tool and call it done).

 

Hope that helps!

John

 

Highlighted
Asteroid

Hi,

 

Many thanks for the prompt and great response.  I was hoping that someone might show me how to unleash the complete power of R graphics by showing how to specify some of the options such as colour and size.

 

Kind regards,

Peter

Highlighted
ACE Emeritus
ACE Emeritus

I added some minimal options to the workflow in the attached; it uses color brewer to choose a color palette, and allows specification of length/width of resulting PNG.  For really advanced stuff, Id switch to plotly though.

Highlighted
Asteroid

Hi,

 

Many thanks for that.  One question though, why are solutions based on saving the R output as an image rather than using a tool output channel?

 

Kind regards,
Peter

Highlighted
ACE Emeritus
ACE Emeritus

A-ha, I learned something new today.  Replace the code in the R tool with the following, and the #1 output will contain the plot in-line.

 

With that, you can remove the block-until-done, etc... and just run the R-tool inline with everything else.

 

#install.packages("RColorBrewer")
library("RColorBrewer")

#pd = pie data
pd <- read.Alteryx("#1", mode="data.frame")

#po - pie options
po <- read.Alteryx("#2", mode="list")

c <- brewer.pal(n=nrow(pd),name=po$pal)

AlteryxGraph(1, width=po$length, height=po$width)
#Insert code to plot graph here

pie(pd$NoOfAccounts, pd$BusinessUnit, col=c)

invisible(dev.off())

 

(Also working on a plotly version; will post once it works inline).

Edit: plotly from the R tool is a no-go for the time being...) 

 

Thanks,

John

 

Highlighted
Asteroid

Hi,

 

Me too thanks to you!

 

Have a great festive break,

Peter

Labels