Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

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

Configuring the R Tool for charting

PeterV
8 - 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

7 REPLIES 7
JohnJPS
15 - Aurora

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

 

PeterV
8 - 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

JohnJPS
15 - Aurora

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.

PeterV
8 - 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

JohnJPS
15 - Aurora

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

 

PeterV
8 - Asteroid

Hi,

 

Me too thanks to you!

 

Have a great festive break,

Peter

AlineCanard
6 - Meteoroid

Hi, thanks a lot for your post. I would like to create an interactive graph thanks to the R tool. The graph output is working with a "simple" ggplot graph, but it fails if I add the ggplotly function to make it become interactive. I think this corresponds to your option 2.

Can someone help me to solve this issue, please?

Labels