如何使画笔工作并将所选点突出显示为红色。
似乎brushedPoints
功能无法正常工作。
library(shiny)
library(ggplot2)
server <- function(input, session, output) {
D = reactive({
brushedPoints(mtcars,input$brush_1, allRows = TRUE)
})
output$Plot = renderPlot({
set.seed(1)
X = D()
X[,"cyl"] = as.character(X[,"cyl"])
ggplot(X,aes_string(x="cyl",y="mpg")) +
geom_boxplot(outlier.shape = NA) +
geom_jitter(aes(color = selected_))+
scale_color_manual(values = c("black","red"),guide=FALSE)
})
output$log = renderPrint({
input$brush_1
})
output$Data = renderPrint({
D()
})
}
ui <- fluidPage(
plotOutput("Plot",brush = "brush_1"),
verbatimTextOutput("Data"),
verbatimTextOutput("log")
)
shinyApp(ui = ui, server = server)
答案 0 :(得分:1)
存在问题是因为您在brushedPoints
和ggplot
中使用了不同的数据:
将列转换为字符
您可以尝试在brushedPoints
library(shiny)
library(ggplot2)
server <- function(input, session, output) {
mt=mtcars
mt[,"cyl"] = as.character(mt[,"cyl"])
D=reactive({brushedPoints(mt,brush = input$brush_1, allRows = TRUE)})
output$Plot = renderPlot({
set.seed(1)
X <- D()
ggplot(X,aes_string(x="cyl",y="mpg")) +
geom_boxplot(outlier.shape = NA) +
geom_jitter(aes(color = selected_))+
scale_color_manual(values = c("black","red"),guide=FALSE)
})
output$log = renderPrint({
input$brush_1
})
output$Data = renderPrint({
D()
})
}
ui <- fluidPage(
plotOutput("Plot",brush = "brush_1"),
verbatimTextOutput("Data"),
verbatimTextOutput("log")
)
shinyApp(ui = ui, server = server)
对于框图绘制工作不简单,因为所有x坐标 - 离散你只能选择它的中间框(点不在实际位置但向左或向右移动 - 因为geom_jitter)
如告诉here,无法使用geom_jitter和刷