0
我有一個閃亮的反應ggvis scatterplot(layer_points)。 現在我想在圖中添加水平線和垂直線,以類似於x/y軸的中值。shiny + ggvis:如何將一條線(中值)添加到scatterplot?
我知道如何計算它,但不知道如何顯示它在同一個情節。 到目前爲止我的代碼:
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)
})
感謝很多幫助的。
我認爲[這](http://stackoverflow.com/questions/31666210/how-can-i-add-a-horizontal-line-in-ggvis)將回答你的問題,無論是答案或評論。 – aosmith
它似乎是一個好主意,使用mutate,然後渲染它的情節。但我無法讓它工作。問題是每次輸入改變時需要計算中位數。如上所示,我知道如何計算即使在反應中的中位數。但我不知道將它添加到情節中。當它在情節制作完成後得到計算後,我如何在情節中獲得它?可能很簡單,但我無法讓它工作。 –