Ich bin neu hier als Benutzer, aber ich habe wie verrückt nach einem Problem gesucht, das ich beim Versuch, eine Datenvisualisierungs-App mit glänzenden in Rstudio zu erstellen aufgetreten.Probleme mit Zoom auf ggplot2 glänzend
Die Sache ist, ich möchte eine .csv lesen, verstehen, es ist Spalten, wählen Sie, welche Spalte ich als x und als y-Achse wollen, plotten sie mit der Art der Grafik, die ich gewählt habe und in der Lage zu vergrößern sekundäre Handlung, wann immer ich will.
Ich bin fast da, die Sache ist, dass der Zoom mit Pinsel, den ich versucht habe, funktioniert nicht richtig funktioniert. Es versteht die Werte der Achse nicht richtig, stattdessen funktioniert es so, als ob beide Achsen nur von 0 bis 1 sind, und dann in der richtigen Weise heranzuzoomen, aber mit dem falschen Xlim und Ylim.
Hier ist meine ui.R:
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")
# )
)
))
Und dann meine 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
}
})
})
einfach die anderen Grundstücke ignorieren, die nicht die geom_point sind. Sobald ich diese Arbeit bekomme, sollten die anderen gut funktionieren, ich denke ...
Vielen Dank, ich habe so einen Schmerz versucht, das herauszufinden! Einige Texte sind in Portugiesisch, aber ich denke alles ist verständlich genug.
Danke für die Antwort, aber ich versuchte, indem diese und es funktioniert immer noch nicht ... Ich bin Denken, anstatt einen Pinsel und Zoom zu tun, ist es vielleicht einfacher, einen Schieberegler für de x und y-Skala zu haben? Ich weiß nicht, wie man hier ein Bild hinzufügt, um zu zeigen, wie es bei mir nicht funktioniert: P –
Sie haben recht! Ich habe meine Antwort mit einer reproduzierbaren Lösung aktualisiert. – qfazille
Vielen Dank! Ich habe jetzt perfekt gearbeitet: D –