Jump to content

Dynamic Graph with R - No graph being generated


Priya Singh

Recommended Posts

I have a data function in R which should create a makko chart. The code successfully creates a chart in R but does not display anything in Spotfire. The code runs without error. Below is the code. (img is the output parameter) :

library(SpotfireUtils)

library(ggplot2)

library(plyr)

library(reshape2)

library(RinR)

df <- data.frame(segment = c("A", "B", "C",

   "D"), segpct = c(40, 30, 20, 10), Alpha = c(60,

   40, 30, 25), Beta = c(25, 30, 30, 25),

   Gamma = c(10, 20, 20, 25), Delta = c(5,

     10, 20, 25))

df$xmax <- cumsum(df$segpct)

df$xmin <- df$xmax - df$segpct

df$segpct <- NULL

dfm <- melt(df, id = c("segment", "xmin", "xmax"))

head(dfm)

dfm1 <- ddply(dfm,.(segment), transform, ymax = cumsum(value))

dfm1 <- ddply(dfm1,.(segment), transform,ymin = ymax - value)

dfm1$xtext <- with(dfm1, xmin + (xmax - xmin)/2)

dfm1$ytext <- with(dfm1, ymin + (ymax - ymin)/2)

p <- ggplot(dfm1, aes(ymin = ymin, ymax = ymax,

   xmin = xmin, xmax = xmax, fill = variable))

p1 <- p + geom_rect(colour = I("grey"))

msg <- ""

img <- RGraph({p1},width=5000, height=500, display=TRUE)

Link to comment
Share on other sites

The plot itself needs to be created within R, not TERR. To enable this, you also need to tell R what data and what packages to use.

This worked for me (well, it generated some plot): I set display=FALSE otherwise I was getting a spurious window.

library(SpotfireUtils)library(ggplot2)library(plyr)library(reshape2)library(RinR) df <- data.frame(segment = c("A", "B", "C","D"), segpct = c(40, 30, 20, 10), Alpha = c(60, 40, 30, 25), Beta = c(25, 30, 30, 25), Gamma = c(10, 20, 20, 25), Delta = c(5,10, 20, 25)) df$xmax <- cumsum(df$segpct)df$xmin <- df$xmax - df$segpctdf$segpct <- NULL dfm <- melt(df, id = c("segment", "xmin", "xmax"))head(dfm)  dfm1 <- ddply(dfm,.(segment), transform, ymax = cumsum(value))dfm1 <- ddply(dfm1,.(segment), transform,ymin = ymax - value) dfm1$xtext <- with(dfm1, xmin + (xmax - xmin)/2)dfm1$ytext <- with(dfm1, ymin + (ymax - ymin)/2) msg <- ""img <- RGraph(print( ggplot(dfm1, aes(ymin = ymin, ymax = ymax, xmin = xmin, xmax = xmax, fill = variable))+ geom_rect(colour = I("grey"))), data='dfm1', packages=c('ggplot2'), width=5000, height=500, display=FALSE)
Link to comment
Share on other sites

Ideally, if you have more than one version of OSR installed, you would tell RinR where Open Source R is installed on your machine: in my case I would add at the start of the script

path='C:/Program Files/R/R-4.1.3/bin/R.exe'

configureREvaluator(REvaluator, FullPath=path)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...