答案 0 :(得分:2)
因为我不确定你想要什么,所以只能猜测2段。
library(shiny)
library(ggplot2)
ui <- shinyUI(fluidPage(
sidebarLayout(
sidebarPanel(
sliderInput("cutoff",
"cutoff",
min = 0.01,
max = 1,
step = 0.01,
value = 0.5)
),
mainPanel(
plotOutput("plot")
)
)
))
server <- shinyServer(function(input, output) {
output$plot <- renderPlot({
df <- data.frame(x = seq(0.01, 1, 0.01), y = seq(0.01, 1, 0.01),
group = c(rep("a", round(input$cutoff * 100)),
rep("b", round(((1-input$cutoff) * 100)))
)
)
labelPos <- data.frame(pos = c(input$cutoff - input$cutoff/2,
(input$cutoff + (1 - input$cutoff)/2)
),
label = c("a", "b")
)
ggplot()+
geom_ribbon(data = df, aes(x=x, ymin = -0.2, ymax = 0.2, fill = group), show.legend = FALSE) +
geom_label(data = labelPos, aes(x = pos, y = 0.3, label = label)) +
coord_cartesian(ylim = c(-1,1)) +
theme(line = element_blank(),
text = element_blank(),
line = element_blank(),
title = element_blank()
)
})
})
shinyApp(ui = ui, server = server)