Alteryx Designer Desktop Discussions

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

R Tool Not Rendering Graph Correctly

jbh1128d1
10 - Fireball

Hello,

 

Has anyone had trouble integrating ggplot2 with the R tool?  I use the following code that loops through variables and graphs them using R Studio:

 

for(i in variable1) {
t <- all_peril1 %>%
arrange(Variable, as.numeric(Level)) %>%
filter(Variable == i) %>%
ggplot(aes(x = as.factor(as.numeric(Level)), group = 1)) +
geom_point(aes(y=factor, color = model)) +
geom_line(aes(y = factor, group = model, color = model)) +
#geom_text(aes(y = factor, label = round(factor, digits =2)),position = position_dodge(width=.09), size = 3, vjust = -.5) +
theme(axis.text.x = element_text(angle = 90, hjust =1)) +
labs(title = "Motor Home Peril Comparison", colour="Peril",x=i,y="Factor")
out <- paste0(as.name(i), ".pdf")
ggsave(out, plot = t, device = "pdf", width = 10, height = 6, units = "in")
print(t)
}

 

rstudiocapture.JPG 

 

When I run the exact same code in Alteryx's r-tool, I get the wrong x axis labels and thus, the wrong graph using the same data set:  The only difference is that I wrapped the code in the AlteryxGraph statement.

 

AlteryxGraph(1, width=2400, height=3000, res=300)
#Insert code to plot graph here


all_peril1 <- all_peril %>% #bind rows within paraenthisis
filter(!is.na(as.numeric(Level))) %>% #filter to what level is not numeric
arrange(Variable, as.numeric(Level)) #arrange by variable and levels

variable1 <- unique(all_peril1$Variable)

for(i in variable1) {
t <- all_peril1 %>%
arrange(Variable, as.numeric(Level)) %>%
filter(Variable == i) %>%
ggplot(aes(x = as.factor(as.numeric(Level)), group = 1)) +
geom_point(aes(y=factor, color = model)) +
geom_line(aes(y = factor, group = model, color = model)) +
#geom_text(aes(y = factor, label = round(factor, digits =2)),position = position_dodge(width=.09), size = 3, vjust = -.5) +
theme(axis.text.x = element_text(angle = 90, hjust =1)) +
labs(title = "Motor Home Peril Comparison", colour="Peril",x=i,y="Factor")
#out <- paste0(as.name(i), ".pdf")
#ggsave(out, plot = t, device = "pdf", width = 10, height = 6, units = "in")
print(t)
}
#pie(c(0.12, 0.3, 0.26), col = c("purple","violetred1","green3"))
invisible(dev.off())

 

alteryxrstudiocapture.JPG

 

 

Does anyone have an idea why this is happening?

 

3 REPLIES 3
PaulN
Alteryx Alumni (Retired)

Hi @jbh1128d1,

 

What version of Alteryx Designer do you use please?

Would you be able to share a package with your workflow and data source?

 

I have run the following test [source: http://tutorials.iq.harvard.edu/R/Rgraphics/Rgraphics.html] but I couldn't recreate your issue.

Environment: 2018.1, R 3.3.2

same behaviour with different resolution for AlteryxGraph

 

In RStudio:

 

ggplot_RStudio.png

 

In Alteryx Designer:

 

ggplot_RLab_code.png

 

 

ggplot_RLab_graph.png

 

 

Paul Noirel

Sr Customer Support Engineer, Alteryx

jbh1128d1
10 - Fireball

Hi @PaulN.

 

I'm using Alteryx Designer version 11.7.4.37815.

 

I can't hand this data over but I ended up using a filter tool and picking which variables I wanted to sort in numeric order and changed those variables values to integers.  Then I run the code twice.  In effect,   the filter tool and change to integer replaced the following code:

 

all_peril1 <- all_peril %>% #bind rows within paraenthisis
filter(!is.na(as.numeric(value))) %>% #filter to what level is not numeric
arrange(Variable, as.numeric(value)) #arrange by variable and levels

PaulN
Alteryx Alumni (Retired)

Hi @jbh1128d1,

 

I am glad you found a way to solve your issue.

 

Thanks for the update,

 

Paul Noirel

Sr Customer Support Engineer, Alteryx

Labels