I am trying to add legend text to a chart, horizontally to appear in the same box as the chart in a shiny application. The code below creates the chart but I cant seem to work out how to add a legend to show up.
output$probability_chart <- renderPlot({
req(input$countrySelectProbabilities)
idx <- which(input$countrySelectProbabilities==FVI_DATA_ALL_COUNTRIES)
plot(x = dates, y=Composite_Probabilities_1_DF[idx, 2:18], type = "l"
, xlab = "Dates", ylab = "Probability", col="black", ylim = c(0, 100), lwd=2)
lines(dates, Banking_Probabilities_1_DF[idx, 2:18], col="red", lwd=2)
lines(dates, Currency_Probabilities_1_DF[idx, 2:18], col="green", lwd=2)
lines(dates, Sovereign_Probabilities_1_DF[idx, 2:18], col="yellow", lwd=2)
lines(dates, Sudden_Stop_Probabilities_1_DF[idx, 2:18], col="blue", lwd=2)
})
Thank you for any help!
This is the code for the box where the chart is contained.
frow3 <- fluidRow(
box(
title = "Z - Scores by Country and Crisis Type"
,selectInput('countrySelectZScore', 'Country', mylist, width = "180px")
,radioButtons("z_score_crisis_type","Crisis Type", c("Global Normalisation" = "Global Normalisation",
"Regional Normalisation" = "Regional Normalisation",
"Own Country Normalisation" = "Own Country Normalisation"), inline=T)
,status = "primary"
,solidHeader = TRUE
,collapsible = TRUE
,plotOutput("zscore_chart")
, height = 600
, width = 6
)
,box(
title = "Probabilities by Country and Crisis Type"
,selectInput('countrySelectProbabilities', 'Country', mylist, width = "180px")
,radioButtons("probability_crisis_type","Crisis Type", c("Global Normalisation" = "Global Normalisation",
"Regional Normalisation" = "Regional Normalisation",
"Own Country Normalisation" = "Own Country Normalisation"), inline=T)
,status = "primary"
,solidHeader = TRUE
,collapsible = TRUE
,plotOutput("probability_chart")
, height = 600
, width = 6
)
)