我的目标是绘制一个具有2条线的图:1条用于过滤数据集,1条用于未过滤数据集。当我输出绘图时,我有一个宽条。我认为我需要将mysample和mysample2组合成一个新变量,并在x轴上绘制它。如果有人有不同的想法,请随时告诉我,我真的被困在如何做到这一点。
此外,我知道x=input$obs完全错误,但我不知道还能尝试什么。
filtered = readxl::read_excel("/Filter.xlsx")
unfiltered = readxl::read_excel("/Unfilter.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),]
ggplot(NULL, aes_string(x = input$obs)) +
geom_col(data = mysample, aes(y = Net_Return)) +
geom_col(data = mysample2, aes(y = Net_Return)) +
labs(y = "Net Return") +
theme_bw() +
scale_y_continuous(labels = scales::dollar)
})
}