GAMA and R - boxplot(s) diagram?

44 views
Skip to first unread message

Sonja Holler

unread,
Feb 27, 2020, 6:15:09 AM2/27/20
to GAMA
Hello everybody,

I would like to know if it is somehow possible to compute boxplot(s) in R directly out of GAMA in the experiment section.

From the examples so far I was able to implement Pearson’s r and have an output graphic box whisker diagram, but it would be much better if I could implement directly code to produce a R diagram with several complete boxplot(s) for comparison in it and save the graphic to the output results folder in GAMA.

I couldn’t find reference models or anything in the GAMA documentation or in the GAMA developer Github site, is there maybe a plugin or a built-in option (I tried boxplotR but it is not recognized) to achieve this? Is it possible with alternative versions of GAMA (Mac OS daily built V1.8.0)?

If so, could you please explain what I have to do or provide an example code?

Thank you in advance,

Sonja




Srirama Bhamidipati

unread,
Feb 28, 2020, 5:31:48 AM2/28/20
to GAMA
Hi

Please see that graphics in R is an independent process to GAMA. You can make it complex if you prefer, but I recommend not to use GAMA to produce R plots. There are two simple options: 
1. you can install a terminal plugin from eclipse market and use it within GAMA ( not in GAML)
2. or you can use a the cmd operator in GAML to use R commands as you would on any OS shell.
3, The complex option is to install R plugin. But for plots, I do not recommend it.

What GAMA allows is exchange of variables between R and GAMA, but not exchange of plots. 


Srirama 

Sonja Holler

unread,
Feb 28, 2020, 5:47:15 AM2/28/20
to gama-p...@googlegroups.com
Hi Srirama,

Thank you for your response. Why wouldn’t you recommend installing a R plugin for plots? Is there a bug? 
I imagined GAMA to deliver the information to R and R building the diagram. 

I do not find excessive information on using GAMA and R in the documentation, can you give me a link where I can learn more about the first two options and what I can achieve with them?

Thank you very much,

Best,

Sonja

-- 
You received this message because you are subscribed to the Google Groups "GAMA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gama-platfor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gama-platform/8abd7613-c59c-4e5a-8926-70c8bedab0ae%40googlegroups.com.

Srirama Bhamidipati

unread,
Feb 28, 2020, 5:52:01 AM2/28/20
to gama-p...@googlegroups.com
The plots you will produce in R do not give any feedback to your gama model. In essence, the plot is just an output of your model and not an input to your model . In such a case, it is futile to make your code complex with no benefit to the model. You can rather do it external to GAMA. hence I do not recommend it " for plots" 

You can just use google or use gama help to look for operators in other suggestions. 


Srirama 
Sonja

To unsubscribe from this group and stop receiving emails from it, send an email to gama-platform+unsubscribe@googlegroups.com.

Sonja Holler

unread,
Feb 28, 2020, 6:06:21 AM2/28/20
to gama-p...@googlegroups.com
I need it only as output, but thank you very much, I will try to look up all options!

Best, Sonja

Am 28.02.2020 um 11:52 schrieb Srirama Bhamidipati <b.sr...@gmail.com>:

The plots you will produce in R do not give any feedback to your gama model. In essence, the plot is just an output of your model and not an input to your model . In such a case, it is futile to make your code complex but no benefit to the model. You can rather do it external to GAMA. hence I do not recommend it " for plots" 
To unsubscribe from this group and stop receiving emails from it, send an email to gama-platfor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gama-platform/506d8711-2a93-4659-b8b1-ca951ff61152%40googlegroups.com.

Sonja Holler

unread,
Feb 29, 2020, 1:28:32 PM2/29/20
to gama-p...@googlegroups.com
Hi everyone,

I’m trying to use the „command“ operator as suggested to built a box plots diagram in R as output. So far, I do not seem to find the right coding. From the documentation I do not understand what is wrong. But I get either:

- Error in console command./bin/bash: -c: line 0: syntax error near unexpected token
- Error in console command. Cannot run program "/bin/bash" (in directory "boxplot ….  error=63, File name too long    or:
- Error in console command. Cannot run program "/bin/bash" (in directory "boxplot()"): error=2, No such file or directory

in many variations.

Can someone explain to me what goes wrong? I would really like to learn and implement this (I have a lot more lists to implement, but wanted to test this starting with two).

string Rscript_directory <- "‎⁨Macintosh HD⁩/⁨Library⁩/⁨Frameworks⁩/⁨R.framework⁩/Versions⁩/3.6⁩/⁨Resources/Rscript⁩";
string R_directory <- "Macintosh HD⁩/⁨Programme/R⁩";



reflex compute_boxplots_in_R when:time>=days_stop+1#day and !(experiment_done)  { 

      map<string, string> boxplot_data <- map<string, string>("a"::string(global_list_a),“b“::string(global_list_b) );

      

      string boxplots <- 'boxplot('+string(global_list_a)+‘,‘+string(global_list_b)+’,
                              main = "comparison",
                              names = c("a", "b"),
                              at = c(1,2)
                              las = 2,
                              horizontal = FALSE,
                              notch = TRUE
                              )';

          string built_boxplots <- command (boxplots);
          //string built_boxplots <- command (Rscript_directory, boxplots, boxplot_data);
          //string built_boxplots <- command (R_directory, boxplots, boxplot_data);
      //string built_boxplots <- Rscript_directory command (boxplots);
      //string built_boxplots <- R_directory command (boxplots);
   }

Thank you very much in advance!

Srirama Bhamidipati

unread,
Feb 29, 2020, 1:30:09 PM2/29/20
to GAMA
Best, Sonja

To unsubscribe from this group and stop receiving emails from it, send an email to gama-platform+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gama-platform/506d8711-2a93-4659-b8b1-ca951ff61152%40googlegroups.com.


Sonja Holler

unread,
Mar 3, 2020, 7:36:15 PM3/3/20
to gama-p...@googlegroups.com
Hi everyone. 

 - First of all, thank you Srirama for the tutorial, I’m trying to make it work but ran into some issues.- 

I’m still not quite there and hope you can help me find a solution. I think the error originates in GAMA, but I’m not sure.

This is what I got so far in the GUI experiment:

    reflex prepare_boxplots_in_R_csv when:time>=days_stop-1#day and !(experiment_step_1)  { 

           save [global_list_a] header:false type:csv to:file_output+country+“/y/GUI-EXPERIMENT_boxplots-input-data_"+country+".csv" rewrite:false;
           save [global_list_b] header:false type:csv to:file_output+country+“/y/GUI-EXPERIMENT_boxplots-input-data_"+country+".csv" rewrite:false;
           …

           write „x_model created "+file_output+country+“/y/GUI-EXPERIMENT_boxplots-input-data_"+country+".csv";
           experiment_step_1 <- true;
    }

    reflex prepare_boxplots_in_R_Rscript when:time>=days_stop+1#day and !(experiment_step_2)  { 

  

           save ["data <- read.table("+Path_to_GAMA_Workspace+“/x/results/"+country+“/y/GUI-EXPERIMENT_boxplots-input-data_"+country+".csv)"] type:csv to:file_output+country+“/y/GUI-EXPERIMENT_Rscript_"+country+".R" rewrite:false;
            

           write „x_model created "+file_output+country+“/y/GUI-EXPERIMENT_Rscript_"+country+".R";          
           experiment_step_2 <- true;

    }

    reflex compute_boxplots_in_R when:time>=days_stop+2#days and R_connected and !(experiment_step_3)  {
       write command(Path_to_GAMA_Workspace+“/x/results/"+country+“/y/GUI-EXPERIMENT_Rscript_"+country+".R");
       write „x_model executed Rscript - find box plots diagram on desktop";      
       experiment_step_3 <- true;
    }

Now I noticed, that GAMA seems to write additional backslashes before every slash in the Rscript, which produces the error: „ \/ is an unkown Escape-Sequence“ when I’m testing it in the R console. Is there a way to prevent this? Or is there another source of this error? It looks like this in the Rscript:

data <- read.table(Macintosh HD⁩\/User⁩\/name⁩\/⁨Desktop\/Gama_Workspace⁩\/x\/results\/countryname\/y\/GUI-EXPERIMENT_boxplots-input-data_countryname.csv)

And GAMA gives me than this error message:
1 occurence in A) GUI experiment simulation0 at cycle 8: Error in console command./bin/bash: Macintosh: command not found

Best,

Sonja

PS: I’m working with macOS Mojave Version 10.14.6 and GAMA V1.8.0 and R 3.6.2. GUI 1.7.0 El Capitan build(7735)












To unsubscribe from this group and stop receiving emails from it, send an email to gama-platfor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gama-platform/1e6838d9-896f-4abb-b7ca-85496bbaa08d%40googlegroups.com.

Srirama Bhamidipati

unread,
Mar 4, 2020, 4:30:02 AM3/4/20
to gama-p...@googlegroups.com
You seem to have an everlasting penchant for making simple things complicated :). Please keep it simple. Do all your R outside of GAMA including the string gymnastics you have in your gaml. Just do all path reading in R, and simply call the script from GAMA as I showed in the tutorial. If you have your header false, how will you work in R? 

Also, do ask a new question for a new problem. This question is no longer a r plot question, it is a path and escape character question.

Please try to do how it is in the tutorial. And for R, perhaps read a bit about subsetting dataframes based on a factor variable so that you dont have to do all these string manipulations in GAMA.

Srirama 
To unsubscribe from this group and stop receiving emails from it, send an email to gama-platform+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gama-platform/1e6838d9-896f-4abb-b7ca-85496bbaa08d%40googlegroups.com.

Sonja Holler

unread,
Mar 4, 2020, 9:26:34 PM3/4/20
to gama-p...@googlegroups.com
Thank you for your tips, I will look it up!

Best, Sonja

Am 04.03.2020 um 10:30 schrieb Srirama Bhamidipati <b.sr...@gmail.com>:

You seem to have an everlasting penchant for making simple things complicated :). Please keep it simple. Do all your R outside of GAMA including the string gymnastics you have in your gaml. Just do all path reading in R, and simply call the script from GAMA as I showed in the tutorial. If you have your header false, who will you work in R? 
To unsubscribe from this group and stop receiving emails from it, send an email to gama-platfor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gama-platform/acb04570-4c2f-4ffe-a984-8938382cce04%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages