我正试图建立一个闪亮的应用程序来重新卷动6面骰子。 a有2个动作按钮。我想实现,每次点击重放按钮将在SAME(!!)图上添加另一个概率线。互动剧情
每个probabilityline应该是另一种颜色(因此,如果你点击它的30倍,你会看到6的30个不同颜色的problines的结果)
与重启按钮,你可以删除所有打印图表在从一开始就可以尝试的阴谋(所以如果一行是altime打印也可以)。
下面是啥子我已创建至今:
library(ggplot2)
library(ggthemes)
library(extrafont)
ui <- fluidPage(
# Application title
titlePanel("Roll the dice"),
# Sidebar with a go_button and a restart_button
sidebarLayout(
sidebarPanel(
actionButton("reroll",
"ReRoll the dice",
width = "100%"),
br(),
br(),
actionButton("restart",
"Restart",
width = "100%")
),
# Show a plot
mainPanel(
plotOutput("plot")
)
)
)
server <- function(input, output) {
output$plot <- renderPlot({
input$reroll
a <- 1:6
b <- 1:1000
eyes <- sample(a,1000,replace=T)
six <- eyes == 6
c <- cumsum(six)/1:1000
df <- data.frame(b , c)
gl <- geom_line(aes(x = b , y = c), size = 0.9, linetype="dashed", colour = "red", alpha = 0.5)
p <- ggplot(data = df) +
xlim(0, 1000) +
ylim(0, 1) +
labs(x="Number of Throws", y="Probability of 6") +
ggtitle("Approximation of Diceprobability") +
theme_fivethirtyeight() + scale_colour_fivethirtyeight() +
theme(axis.title = element_text(family="Atlas Grotesk Regular"),
legend.position="bottom", legend.direction="horizontal",
legend.title=element_blank(),
plot.title=element_text(family="Atlas Grotesk Medium"),
legend.text=element_text(family="Atlas Grotesk Regular"),
text=element_text(family="DecimaMonoPro"))
p + gl
})
}
shinyApp(ui=ui, server = server)
问题:
我如何可以绘制在同一个图(不同的线,你知道...我点击30倍它在同一个图中构建30行)
如何编程它,每行有另一种颜色?
我该如何“删除”它与我的重启按钮可以有另一个尝试?
我会很高兴每个帮助在那里:-)
非常感谢。
非常感谢!这就是我的搜索!谢谢 :-) –