Hello!
I am working on a research project right now and neither the professor I work with or myself knows very much about coding in R. We have been trying to figure out how to compare two segments of data we have collected. We want to use sliders to narrow our data set. I have attached the R code and csv file, but I will talk more specifically about our issue and my process.
- I make a summary data set using information from the CSV I attached. This involves separating the data into segments that are a result of our collection method
- I use two sliders to select the ranges we want to do analysis with (filtered1.data() and filtered1.data())
#Range 1
sliderMin1 <- reactive ({ input$sliderRange1[1] })
sliderMax1 <- reactive ({ input$sliderRange1[2] })
#Range 2
sliderMin2 <- reactive ({ input$sliderRange2[1] })
sliderMax2 <- reactive ({ input$sliderRange2[2] })
#Filter data
filtered1.data <- reactive({ #reactive object updates every time the user changes the slider
req(input$sliderRange1)
filter(final.data(), seg2()$Number>input$sliderRange1[1] & seg2()$Number<input$sliderRange1[2])
})
filtered2.data <- reactive({ #reactive object updates every ti
me the user changes the slider
req(input$sliderRange2)
filter(final.data(), seg2()$Number>input$sliderRange2[1] & seg2()$Number<input$sliderRange2[2])
})
- I use the new data set to plot the specific range but I get this error that I cannot get rid of!
#Code for L1_1 plot
output$L1_1 <- renderPlot({
ggplot(filtered1.data())+
geom_point(aes(x = seg2()$Number, y = seg2()$L1), color = "blue")+
geom_smooth(aes(x = seg2()$Number, y = seg2()$L1), method = "lm", se=FALSE, color="black", formula =y ~ x)+
labs(title = "L1 vs. Number for region 1",
x = "Number",
y = "L1")+
#edit text sizes for title and axes labels
theme(plot.title = element_text(size=24,face="bold"),
axis.title.x = element_text(size=14),
axis.title.y = element_text(size=14))
})
Aesthetics must be either length 1 or the same as the data (603): x and y
Right now I am just trying to get this method to work for one plot. I would really appreciate some guidance on how I could get this to work.
Best