Hello Everyone,
I hope this is the right place to ask this question.
I have a simple data frame with the following variables: "Date", "Athlete", "Weight"
I am currently creating a Rshiny dashboard. One of the goals is to graph Athlete Weights over time. There are multiple athletes in the data set. My code currently filters the data by an athlete select input and graphs that athlete's data over time (code included below)
However, I would like to provide additional information regarding whether the athlete's weight variation is acceptable or not acceptable. What I would like to do is have a simple line graph of Athlete 1 weight over time.. and in the background of the ggplot have the background color change dependent on the whole data set (all athletes' weight standard deviation (SD of the data frame will be continuously changing with additional weight inputs)).
I envision this as a linegraph with a light, semi-transparent green background for "within 1 SD", a light, semi-transparent orange background for "between 1 and 2 SD" and a light, semi-transparent red background for ">2 SD"
I hope this makes sense, if not I would love to improve my explanation. Below is my current server code.
Thank you for your time and help.
'''
server <- function(session, input, output) {
output$plot1 <- renderPlotly({
df_filtered <- filter(df, Date >= format(input$daterange[1]) & Date <= format(input$daterange[2])) %>%
filter(Playername == input$Playernameinput)
print(
ggplotly(
ggplot(df_filtered, aes(x= Date, y= Weight)) +
geom_point(size=1.25)+
geom_line(color = "Red")+
theme_bw()+
theme(axis.line = element_line(colour = "black"),
axis.title = element_text(face="bold"),
axis.text.x = element_text(angle = 45, hjust=1)) +
scale_x_date(date_labels = "%b/%d/%y")
))
})
}
'''