Skip to content

Commit c4e26ae

Browse files
committed
add option for density plots (#51 and #58)
1 parent 8366d26 commit c4e26ae

2 files changed

Lines changed: 26 additions & 11 deletions

File tree

inst/shiny/server.R

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,29 +1454,38 @@ output$attrhist <- renderPlot({
14541454
if(nplots == 1){
14551455
par(mfrow = c(1, 1))
14561456
lvls <- length(unique(nwdf()[[attrname]]))
1457-
if(attrname %in% numattr() & lvls > 9){
1458-
tab <- hist.info(nwdf()[[attrname]], breaks = 10)
1457+
if(input$attrhistaxis == "density" & attrname %in% numattr() & lvls > 9){
1458+
plot(density(nwdf()[[attrname]]), main = attrname,
1459+
col = "#076EC3", lwd = 2)
14591460
} else {
1460-
tab <- table(nwdf()[[attrname]])
1461-
}
1462-
if(input$attrhistaxis == "Percents"){
1463-
tab <- tab/sum(tab)
1461+
if(attrname %in% numattr() & lvls > 9){
1462+
tab <- hist.info(nwdf()[[attrname]], breaks = 10)
1463+
} else {
1464+
tab <- table(nwdf()[[attrname]])
1465+
}
1466+
if(input$attrhistaxis == "percent"){
1467+
tab <- tab/sum(tab)
1468+
}
1469+
barplot(tab, xlab = attrname, col = histblue)
14641470
}
1465-
barplot(tab, xlab = attrname, col = histblue)
14661471
} else {
14671472
r <- ceiling(nplots/2)
14681473
par(mfrow = c(r, 2))
14691474
for(a in attrname){
14701475
lvls <- length(unique(nwdf()[[a]]))
1471-
if(a %in% numattr() & lvls > 9){
1476+
if(input$attrhistaxis == "density" & a %in% numattr() & lvls > 9){
1477+
plot(density(nwdf()[[a]]), main = a, col = "#076EC3", lwd = 2)
1478+
} else {
1479+
if(a %in% numattr() & lvls > 9){
14721480
tab <- hist.info(nwdf()[[a]], breaks = 10)
14731481
} else {
14741482
tab <- table(nwdf()[[a]])
14751483
}
1476-
if(input$attrhistaxis == "Percents"){
1484+
if(input$attrhistaxis == "percent"){
14771485
tab <- tab/sum(tab)
14781486
}
14791487
barplot(tab, xlab = a, col = histblue)
1488+
}
14801489
}
14811490
}
14821491
})

inst/shiny/ui.R

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,9 +505,15 @@ fluidRow(
505505
dataTableOutput("attrtbl")
506506
),
507507
conditionalPanel('input.attrview == "histogram"',
508+
tags$label("Type of plots"),
509+
helpText("Density plots will only be created for",
510+
"numeric attributes with more than nine",
511+
"levels."),
508512
selectInput("attrhistaxis",
509-
label = "Y-axis units",
510-
choices = c("Counts", "Percents")),
513+
label = NULL,
514+
choices = c("Barplot: counts" = "count",
515+
"Barplot: percents" = "percent",
516+
"Density plot" = "density")),
511517
uiOutput("attrhistplotspace"))
512518

513519
),

0 commit comments

Comments
 (0)