Hi all
I am making a plot in Shiny, based in 3 columns of my dataset. I want to add an legend, but I can figure out how to do this?
This is my code, first I generate a dataframe (MIN, MEAN, MAX) with the while loop, then I Try to plot it, but I want a legend that says blue is min, orange is mean and red is max.
#Create a Empty DataFrame with 0 rows and n columns
columns = c("Hour","Low TAT", "Mean", "High TAT")
df_scatterplot = data.frame(matrix(nrow = 0, ncol = length(columns)))
colnames(df_scatterplot) = columns
counter <- 0
while(counter < 24){
df_scatterplot[nrow(df_scatterplot) + 1,] = c(counter,
quantile(df1_filtered$TAT[df1_filtered$Hours == counter], probs = 0.01),
mean(df1_filtered$TAT[df1_filtered$Hours == counter]),
quantile(df1_filtered$TAT[df1_filtered$Hours == counter], probs = 0.99))
counter = counter +1
}
update_busy_bar(99)
update_busy_bar(100)
ggplot(data = df_scatterplot) +
geom_line(aes(x=df_scatterplot$Hour, y=df_scatterplot$`Low TAT`), color = "blue") +
geom_point(aes(x=df_scatterplot$Hour, y=df_scatterplot$`Low TAT`), color = "blue") +
geom_text(x=df_scatterplot$Hour, y=df_scatterplot$`Low TAT`, label = round(df_scatterplot$`Low TAT`, digits = 2), vjust = -1) +
geom_line(aes(x=df_scatterplot$Hour, y=df_scatterplot$`High TAT`), color = "red") +
geom_point(aes(x=df_scatterplot$Hour, y=df_scatterplot$`High TAT`), color = "red") +
geom_text(x=df_scatterplot$Hour, y=df_scatterplot$`High TAT`, label = round(df_scatterplot$`High TAT`, digits = 2), vjust = -1) +
theme(axis.text.x = element_text(face = "bold", color = "#993333", size = 15),
axis.text.y = element_text(face = "bold", color = "#993333", size = 15),
axis.line = element_line(color = "#993333", size = 1)) +
scale_x_continuous(breaks=seq(0,23,1)) +
xlab("Hours in a day") + ylab("TAT")
Thank you!