Alteryx Designer Desktop Discussions

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

R Tool - Writing GGPLOTs with a loop

jbh1128d1
10 - Fireball

Hello,

 

I'm trying to reproduce in Alteryx what I produce in R-Studio.  Basically, I take a model summary of tidy data and loop through the field name to produce multiple ggplot2 graphs, only Alteryx is not recognizing my loops.   

 

Here is my code:

# Read in the data from Alteryx into R
the_data <- read.Alteryx("#1", mode="data.frame")

 

write.Alteryx(the_data, 2)

 

variable <- unique(the_data$Field_Name[-1])

 

AlteryxGraph(1, width=2400, height=3000, res=300)
#Insert code to plot graph here
for (i in variable){
  j <- the_data %>%
    filter(Field_Name == i)
    t <- ggplot(data = j, aes(x = Field_Value, group = Field_Name)) +
      geom_bar(data = j, aes(y = Percent), fill = "yellow", color = "blue", stat = "identity") +
      geom_text(aes(y = Percent, label = Percent), position = position_dodge(width=.09), size = 3, vjust = -.5) +
      theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
      xlab(j$Field_Name) +
      geom_line(aes(y = Term*10), color = "red") +
      geom_point(aes(y = Term*10), color = "blue") +
      geom_text(aes(y = Term*10, label=Term), size = 3, vjust = -1) + 
      scale_y_continuous(sec.axis = sec_axis(~./10, name = "Factor"))
    print(t)
}
#pie(c(0.12, 0.3, 0.26), col = c("purple","violetred1","green3"))
invisible(dev.off())

 

Again, this works perfectly with RStudio.  I can't post this data but here is a short look to give you an idea.  Term is not shown here but consider Coefficient as term. datalook.PNG

1 REPLY 1
jbh1128d1
10 - Fireball

Figured it out. It might help to change "write.Alteryx(the_data, 2)" to "the_data <- write.Alteryx(the_data, 2)"  Worked like a charm then.  

Labels