Priya Singh Posted May 7, 2023 Share Posted May 7, 2023 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$segpctdf$segpct <- NULLdfm <- 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 More sharing options...
Gaia Paolini Posted May 9, 2023 Share Posted May 9, 2023 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 More sharing options...
Priya Singh Posted May 9, 2023 Author Share Posted May 9, 2023 Hi Gaia,thank you for the response but I get an error saying that ggplot2 is not installed. I have attached the error message. TIA. Link to comment Share on other sites More sharing options...
Gaia Paolini Posted May 9, 2023 Share Posted May 9, 2023 RinR executes Open Source R code, using what is installed on your machine. The library ggplot2 needs to be installed in your Open Source R, the one that RinR points to. Link to comment Share on other sites More sharing options...
Gaia Paolini Posted May 9, 2023 Share Posted May 9, 2023 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 scriptpath='C:/Program Files/R/R-4.1.3/bin/R.exe'configureREvaluator(REvaluator, FullPath=path) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now