【发布时间】:2016-04-15 13:54:58
【问题描述】:
我有一个闪亮的反应性 ggvis 散点图 (layer_points)。 现在我想在图中添加一条水平线和垂直线,以类似于 x/y 轴的中值。
我知道如何计算它,但不知道如何在同一个图中显示它。 到目前为止我的代码:
vis <- reactive({
# Lables for axes
xvar_name <- names(axis_vars)[axis_vars == input$xvar]
yvar_name <- names(axis_vars)[axis_vars == input$yvar]
xvar <- prop("x", as.symbol(input$xvar))
yvar <- prop("y", as.symbol(input$yvar))
gegevens %>%
ggvis(x = xvar, y = yvar) %>%
layer_points(size := 50, size.hover := 200,
fillOpacity := 0.2, fillOpacity.hover := 0.5,
stroke = ~bron, key := ~Project.ID) %>%
add_tooltip(gegevens_tooltip, "hover") %>%
add_axis("x", title = xvar_name, format='d', grid = FALSE) %>%
add_axis("y", title = yvar_name, format='d', grid = FALSE) %>%
add_legend("stroke", title = "Gegevens van:", values = c("A", "B")) %>%
scale_numeric("x", trans = "log", expand=0) %>%
scale_numeric("y", trans = "log", expand=0) %>%
scale_nominal("stroke", domain = c("A", "B"),
range = c("blue", "#aaa")) %>%
set_options(width = 600, height = 600)
})
vis %>% bind_shiny("plot1")
计算我使用的中位数:
output$defects <- renderText ({
d <- median(gegevens()$Total.Defects.Delivered)
paste("de mediaan voor totaal aantal Defects is:", d)
})
非常感谢您的帮助。
【问题讨论】:
-
我认为this 会回答你的问题,无论是答案还是评论。
-
使用 mutate 然后将其渲染到情节上似乎是个好主意。但我就是无法让它工作。问题是每次输入更改时都需要计算中位数。如上所示,即使在反应式中,我也知道如何计算中位数。但我不知道是否将其添加到情节中。因为它是在情节制作后计算出来的,我如何在情节中得到它?可能很简单,但我就是无法让它工作。
标签: r scatter-plot ggvis shiny