Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.
Free Trial

Alteryx Designer Desktop Discussions

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

Create pie chart in R the Tool

agcruz
7 - Meteor

I need assistance in creating a simple pie chart in the R tool in Alteryx.

 

My end goal is to create a Harvey ball where the 2 colors used are red and green. Red = loss and Green = Win. (example below)

The Example I am trying to replicateThe Example I am trying to replicate

 

 

The issue I am facing is that the R Tool is not recognizing my input for the Red and Green. It outputs the colors Orange and Blue instead. (Example below).

 

The R Tool errorThe R Tool error

Here is my R Code:

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

AlteryxGraph(2, width=2400, height=3000, res=300)

pie(df$Value, df$Name, main = "Banner1", col = df$Color)

invisible(dev.off())

 

3 REPLIES 3
danilang
19 - Altair
19 - Altair

Hi @agcruz 

 

Are your color names in lower case as in this example from http://www.r-tutor.com/elementary-statistics/qualitative-data/pie-chart

 

> colors = c("red", "yellow", "green", "violet", 
+   "orange", "blue", "pink", "cyan") 
> pie(school.freq,             # apply the pie function 
+   col=colors)                # set the color palette

 

Dan 

agcruz
7 - Meteor

I have used the lowercase text for the colors but still get the same error. 

agcruz
7 - Meteor

I got my code to work.

 

I figured out that I should an extra line in R to create a field with the color selection in stead of creating the field before the R tool. The code is below.

 

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

AlteryxGraph(1, width=2400, height=3000, res=300)

df$color <- ifelse(df$ColorNumber == 1,"green3","red2")

pie(df$Value, df$Name, main = df$ChartTitle, col = df$color)

invisible(dev.off())

 

Thanks!

Labels
Top Solution Authors