RStudio에서 슬라이더가있는 대화 형 그래프를 그리는 방법이 있는지 궁금합니다. 나는 직선을 그려보고 싶습니다. 그리고 절편과 기울기를 변경하는 슬라이더를 만들고 싶습니다. 예를 들어 this과 같이 입력하십시오. 여기서 a와 b는 제가 원하는만큼 자유롭게 움직일 수있는 제 슬라이더입니다.R의 대화식 그래프, 직선 변경 매개 변수
0
A
답변
0
이 작동합니다 : 반짝의
#save this script as app.R
library(shiny)
ui <- fluidPage(
# Application title
titlePanel("Linear Equation App"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput(inputId = "slope",label = "Slope:",
min = 0,max = 100,value = 0),
sliderInput(inputId = "intercept",label = "Intercept",
min = -100,max = 100,value = 0)
),
mainPanel(
plotOutput("lineplot")
)
)
)
server <- function(input, output) {
output$lineplot <- renderPlot({
x <- seq(from = 0, to = 100, by = 0.1)
y <- x*input$slope + input$intercept
plot(x,y)
})
}
shinyApp(ui = ui, server = server)
또 다른 옵션은 반짝 응용 프로그램을 만드는 것입니다 : 여기
library(manipulate)
x <- seq(from = 0, to = 100, by = 0.1)
manipulate(plot(x,slope*x+intercept), slope = slider(0, 100),
intercept = slider(-100,100))
플롯 출력의 스크린 샷입니다 앱.

0
다음은 반짝이는 + ggplot2를 사용한 간단한 예입니다. x1 = 1, x2 = 2 및 y가 y1 = mx1 + b를 사용하는 슬라이더로부터의 입력을 기반으로 계산되는 선을 생성하기에 충분히 쉽습니다. y2 = m × 2 + b.
library(ggplot2)
library(shiny)
ui <- fluidPage(
strong("This is an interactive line"),
sliderInput("slope", "Define slope:", min = -100, max = 100, value = 0, step = 0.01),
sliderInput("intercept", "Define intercept:", min = -10000, max = 10000, value = 0, step = 1),
plotOutput("linePlot"))
server <- function(input, output) {
output$linePlot <- renderPlot({
ggplot(mapping = aes(x = c(1, 2),
y = c(input$slope*1+input$intercept, input$slope*2+input$intercept))) +
geom_line()
})
}
shinyApp(ui, server)