Click here to Skip to main content
15,434,829 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am developing an application in R shiny and I would like to make a graph dynamic by adding points, error bar, and lines using the ggplot2 package R. 

The columns of my dataframes have no names because I merge Excel files uploaded by the user using R cbind.data.frame(), so the dataframes depend on how many files the user uploads. This also affects the ggplot. 

But I know the number of columns that separate the data I have to use in my dataframe so I created dynamic variables named y, k, and z that increment each time for the choice of the right columns in the respective dataframes. 

I found this code and I adapted it to my code but I have the following errors

Error in check_required_aesthetics: geom_line requires the following missing aesthetics: y

Error in check_aesthetics: Aesthetics must be either length 1 or the same as the data (57): ymin and ymax


What I have tried:

plotAllLayers<-function(df){
    y<-0
    z<-1
    k<-0
    p <- ggplot(data=df, aes(x=df[,1], y=df[,2])) + labs(x="deltaExWL (nm)",y="CSM")

    for(i in 1:input$nberspl_one){
      
      p <- p + geom_point(aes(x=df[,1], y= df[,y+2]), color = "blue")+
              geom_errorbar(aes(ymin= df[,y+2] - df[,y+3], ymax= df[,y+2] + df[,y+3] ), color = "blue")+
              geom_line(data=df_fitted, aes(x=df_fitted[,1], y = df_fitted[,k+3]), color = "blue")

      z<- z+1
      y<- y+3
      k<- k+4
    }
    return(p)
  }
  plotAllLayers(Alldfplt)
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900