저는 사용자로서 여기 새로 왔지만 Rstudio에서 반짝이는 데이터 시각화 응용 프로그램을 만들려고 할 때 발생하는 문제에 대해 미친 듯이 검색했습니다.ggplot2 확대/축소를 사용하는 데 문제가 있습니다.
문제는, .csv를 읽고, 열을 이해하고, x 및 y 축으로 원하는 열을 선택하고 선택한 그래프 유형으로 플롯하고 내가 원할 때마다 보조 음모.
저는 거의 다 왔는데, 제가 시도한 브러시 줌이 제대로 작동하지 않습니다. 그것은 축의 값을 정확하게 이해하지 못합니다. 대신에 축이 0에서 1까지만있는 것처럼 작동 한 다음 잘못된 xlim 및 ylim으로 올바른 방법으로 확대/축소합니다.
library(shiny)
library(ggplot2)
base = read.csv("TESTE.csv", sep = ";")
tipos <- c("Dispersão", "Histograma", "Boxplot", "Área")
shinyUI(fluidPage(
titlePanel("MGM"),
sidebarLayout(
sidebarPanel(
selectInput("selectedColX", "Select colum for X axis", choices = colnames(base), selected = colnames(base)[7]),
selectInput("selectedColY", "Select colum for Y axis", choices = colnames(base), selected = colnames(base)[4]),
selectInput("selectedColor", "Select colum for colour axis", choices = colnames(base), selected = colnames(base)[6]),
selectInput("seletedGraph", "Select type of graph", choices = tipos, selected = tipos[1])
),
fluidRow(
column(width = 12, class = "well",
h4("Left plot controls right plot"),
fluidRow(
column(width = 10,
plotOutput("Disp", height = 300,
brush = brushOpts(
id = "Disp_brush",
clip = TRUE,
resetOnNew = TRUE
)
)
),
column(width = 10,
plotOutput("DispZoom", height = 300)
)
)
)
)
# mainPanel(
#
# plotOutput("Hist"),
# plotOutput("Box"),
# plotOutput("Ar")
# )
)
))
그리고 내 Server.R :
library(shiny)
library(ggplot2)
base = read.csv("TESTE.csv", sep = ";")
tipos <- c("Dispersão", "Histograma", "Boxplot", "Área")
shinyServer(function(input, output) {
output$Disp <- renderPlot({
validate(need(input$seletedGraph=="Dispersão", message=FALSE))
y_axis <- input$selectedColY
x_axis <- input$selectedColX
color_axis <- input$selectedColor
gg <- ggplot(base, aes_string(x = x_axis, y = y_axis, color = color_axis))
gg <- gg + geom_point()
plot(gg)
})
ranges2 <- reactiveValues(x = NULL, y = NULL)
output$DispZoom <- renderPlot({
validate(need(input$seletedGraph=="Dispersão", message=FALSE))
y_axis <- input$selectedColY
x_axis <- input$selectedColX
color_axis <- input$selectedColor
gg <- ggplot(base, aes_string(x = x_axis, y = y_axis, color = color_axis)) + geom_point() + coord_cartesian(xlim = ranges2$x, ylim = ranges2$y)
plot(gg)
})
output$Hist <- renderPlot({
validate(need(input$seletedGraph=="Histograma", message=FALSE))
y_axis <- input$selectedColY
x_axis <- input$selectedColX
color_axis <- input$selectedColor
gg <- ggplot(base, aes_string(x = x_axis))
gg <- gg + geom_histogram()
gg
})
output$Box <- renderPlot({
validate(need(input$seletedGraph=="Boxplot", message=FALSE))
y_axis <- input$selectedColY
x_axis <- input$selectedColX
color_axis <- input$selectedColor
gg <- ggplot(base, aes_string(x = x_axis, y = y_axis, color = color_axis))
gg <- gg + geom_boxplot()
gg
})
output$Ar <- renderPlot({
validate(need(input$seletedGraph=="Área", message=FALSE))
y_axis <- input$selectedColY
x_axis <- input$selectedColX
color_axis <- input$selectedColor
gg <- ggplot(base, aes_string(x = x_axis, y = y_axis, color = color_axis))
gg <- gg + geom_area()
gg
})
observe({
brush <- input$Disp_brush
if (!is.null(brush)) {
ranges2$x <- c(brush$xmin, brush$xmax)
ranges2$y <- c(brush$ymin, brush$ymax)
} else {
ranges2$x <- NULL
ranges2$y <- NULL
}
})
})
는 그냥 geom_point 아닌 다른 플롯을 무시
여기 내 ui.R입니다. 이 작업을하면 다른 사람들도 잘 작동 할 것입니다. 내 생각에 ...
고마워요, 이걸 알아 내려고 고맙습니다. 일부 텍스트는 포르투갈어로되어 있지만, 모든 것이 충분히 이해할 수 있다고 생각합니다.
감사합니다,하지만 난이 추가 시도하고 아직도 난 ... 작동하지 않습니다 대신 브러시를 사용하고 확대하는 것이 생각되면 아마도 x 및 y 크기의 슬라이더가있는 것이 더 쉽습니다. 어떻게 나를 위해 일하지 않는지 보여주기 위해 그림을 여기에 추가하는 방법을 모르겠습니다. P –
맞습니다! 재현 가능한 솔루션으로 내 대답을 업데이트했습니다. – qfazille
정말 고마워요! 나는 지금 완벽하게 일했다 : D –