0

I am writing some plotting functions for a large time series database (extract of the data). I wrote a code to plot all the parameters (columns) against the time (first column of the data frame) linked to a given cycle (data frame). I am using a loop to plot all the parameters at once. The problem is that when I call the function, that uses the package ggplot2, only 20 plots out of the needed 34 appear in different windows. I obtain all plots between plot of parameter 11 (Gas_Flow_Mon_01) and plot of the last parameter 34 (Timer_24_Resettable_Value). I don't know if the problem lies within my code or if 20 is the full capacity of windows displayed at once using ggplot2? I have heard of functions like dev.off() but don't know if they would help in dealing with this issue.

# Function plotting all the parameters for one cycle using the indexes of the parameters and the cycle : 
#  `plot_cycle_allparameters_interactive()`
library(plotly)
library(tidyr)

plot_cycle_allparameters_interactive <- function(datafile,Cycle_index){
  Cycle_name = names(datafile)[Cycle_index]
  Cycle_data = datafile[[Cycle_name]]
# Cycle_data is the datafile studied that consists of multiple columns, each one representing a parameter

  for(i in 2:length(Cycle_data)){
# looping through all the columns that represent a parameter
    figure_interactive <- ggplot(Cycle_data, aes(x =Time,y = Cycle_data[,i], group= 1)) +
    geom_line(color='blue') 

    print(ggplotly(figure_interactive))
    dev.off()
  }
}
Zaynab
  • 1
  • 4
  • See if it's possible to rephrase the question with [mcve](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example?rq=1) principles. Notable, I think the problem may still be evident after stripping a lot out of this function, such as the scale and labs calls, and maybe even ggplotly. – wibeasley Jun 22 '18 at 14:46
  • Thanks! I tried to do as you suggested, hope the question is a bit clearer? – Zaynab Jun 22 '18 at 15:04
  • Read through that link another time or two. There are several aspects to this code, and the question would really benefit fro (but not exclusively) a dataset, a picture of what it looks like on your computer, and (if possible) what you want it to look like roughly. I think I see a problem in the `aes()` call, but we're kinda blind because we don't know what the dataset contains. And are you sure the ggplotly is needed to demonstrate the problem? – wibeasley Jun 22 '18 at 15:13
  • The database is very large so I included a screenshot (though not sure it would help). Should I rewrite the problem with another simpler example? The question behind is whether using a for loop with ggplotly limits the number of windows displayed or if there is a problem within my code. What would the problem with the aes() function be? I need ggplotly because the function has to allow engineers to provide real-time analysis of what is going on based on the graphs of the parameters of interest. Thanks for the help! – Zaynab Jun 22 '18 at 15:38
  • Yes, I include a smaller & simpler dataset (but not too simple) to recreate the problem. For something like `Cycle_data[,i]`, I think you'd need `aes_string()` (and also change `Time` to `"Time"`. But I don't know why that would work for the first 20 plots, but not the last 12. – wibeasley Jun 22 '18 at 16:21

0 Answers0