R 图形下方着色多边形中的间隙仅在光泽aps中正态分布的平均值处

R 图形下方着色多边形中的间隙仅在光泽aps中正态分布的平均值处,r,graph,shiny,polygon,R,Graph,Shiny,Polygon,我正在写一个闪亮的应用程序,它根据滑块的输入创建多边形。代码在这里 SATmean=1000 SATsd=200 Score <- round ((seq(-3,3,length=120)*SATsd + SATmean), -1) y <- dnorm(Score,SATmean,SATsd) percentile <- round(pnorm((Score-mean)/sd)*100,2) ui <- fluidPage ( plotOutput (outp

我正在写一个闪亮的应用程序,它根据滑块的输入创建多边形。代码在这里

SATmean=1000
SATsd=200
Score <- round ((seq(-3,3,length=120)*SATsd + SATmean), -1)
y <- dnorm(Score,SATmean,SATsd)
percentile <- round(pnorm((Score-mean)/sd)*100,2)

ui <- fluidPage (
    plotOutput (outputId = "graph"),
    sliderInput (inputId = "SATscore",
        label = "Select your SAT score", step = 10,
        value = 1200, min = 400, max = 1600)
        )
server <- function(input,output){
        output$graph <- renderPlot({
        plot(Score, y, type="l")
        polygon(c(Score[Score>=input$SATscore],rev(Score[Score>=input$SATscore])),
              c(rep(0,length(Score[Score>=input$SATscore])),rev(y[Score>=input$SATscore])),col="skyblue")
        polygon(c(Score[Score<=input$SATscore],rev(Score[Score<=input$SATscore])),
              c(rep(0,length(Score[Score<=input$SATscore])),rev(y[Score<=input$SATscore])),col="magenta")
        })
}

shinyApp(ui = ui, server = server)
SATmean=1000
SATsd=200

分数问题来自你的
分数
向量,如果你打印它,你可以看到在所有向量中,除了一个(990-1010)之外,两个数字之间的差距是10:

这导致第一个多边形在990处结束,第二个多边形在1010处开始,因此存在间隙

要解决此问题,只需增加此向量的长度(150而不是120):

得分
Score
[1]  400  410  420  430  440  450  460  470  480  490  500  510  520  530  540  550  560  570  580  590  600  610  620  630  640  650
[27]  660  670  680  690  700  710  720  730  740  750  760  770  780  790  800  810  820  830  840  850  860  870  880  890  900  910
[53]  920  930  940  950  960  970  980  990 1010 1020 1030 1040 1050 1060 1070 1080 1090 1100 1110 1120 1130 1140 1150 1160 1170 1180
[79] 1190 1200 1210 1220 1230 1240 1250 1260 1270 1280 1290 1300 1310 1320 1330 1340 1350 1360 1370 1380 1390 1400 1410 1420 1430 1440
[105] 1450 1460 1470 1480 1490 1500 1510 1520 1530 1540 1550 1560 1570 1580 1590 1600
Score <- round ((seq(-3,3,length=150)*SATsd + SATmean), -1)