唯一的问题是样本没有对excel文件中的Net Return列求和,而是使用sliderInput进行了更改。我尝试使用总和并总结,但我没有得到结果。实际上,如果没有scale_y_continuous中断函数,它会绘制一系列值(这就是我所知道的并不是我想做的事情)。任何帮助表示赞赏!谢谢!
UI:
filtered = readxl::read_excel("/Users/Filter2.xlsx")
unfiltered = readxl::read_excel("/Users/Unfilter2.xlsx")
ui = fluidPage(
sliderInput("obs", "Number of Observations", value = 550, min = 100, max = 1000),
plotOutput("filter")
)
服务器:
server = function(input, output) {
output$filter = renderPlot({
mysample = filtered[sample(1:nrow(filtered), input$obs,
replace=FALSE),]
mysample2 = unfiltered[sample(1:nrow(unfiltered), input$obs,
replace=FALSE),]
tbl = bind_rows(Filtered = mysample, Unfiltered = mysample2,
.id="type")
#sum(mysample)
#sum(mysample2)
#summarise(mysample = sum(mysample),
# mysample2 = sum(mysample2))
ggplot(tbl, aes(x = type, fill = type)) +
geom_col(aes(y = Net_Return)) +
labs(x = "Type", y = "Net Return") +
theme_bw() +
theme(legend.position = "none") +
scale_y_continuous(labels = scales::dollar, limits = c(0, 2500000))
})
}