Skip to content

Commit 6e27a6e

Browse files
committed
Merge pull request #59 from statnet/production
additions to attribute histograms
2 parents c4122b4 + c4e26ae commit 6e27a6e

2 files changed

Lines changed: 29 additions & 5 deletions

File tree

inst/shiny/server.R

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,23 +1453,38 @@ output$attrhist <- renderPlot({
14531453
if(nplots == 1){
14541454
par(mfrow = c(1, 1))
14551455
lvls <- length(unique(nwdf()[[attrname]]))
1456-
if(attrname %in% numattr() & lvls > 9){
1457-
tab <- hist.info(nwdf()[[attrname]], breaks = 10)
1456+
if(input$attrhistaxis == "density" & attrname %in% numattr() & lvls > 9){
1457+
plot(density(nwdf()[[attrname]]), main = attrname,
1458+
col = "#076EC3", lwd = 2)
14581459
} else {
1459-
tab <- table(nwdf()[[attrname]])
1460+
if(attrname %in% numattr() & lvls > 9){
1461+
tab <- hist.info(nwdf()[[attrname]], breaks = 10)
1462+
} else {
1463+
tab <- table(nwdf()[[attrname]])
1464+
}
1465+
if(input$attrhistaxis == "percent"){
1466+
tab <- tab/sum(tab)
1467+
}
1468+
barplot(tab, xlab = attrname, col = histblue)
14601469
}
1461-
barplot(tab, xlab = attrname, col = histblue)
14621470
} else {
14631471
r <- ceiling(nplots/2)
14641472
par(mfrow = c(r, 2))
14651473
for(a in attrname){
14661474
lvls <- length(unique(nwdf()[[a]]))
1467-
if(a %in% numattr() & lvls > 9){
1475+
if(input$attrhistaxis == "density" & a %in% numattr() & lvls > 9){
1476+
plot(density(nwdf()[[a]]), main = a, col = "#076EC3", lwd = 2)
1477+
} else {
1478+
if(a %in% numattr() & lvls > 9){
14681479
tab <- hist.info(nwdf()[[a]], breaks = 10)
14691480
} else {
14701481
tab <- table(nwdf()[[a]])
14711482
}
1483+
if(input$attrhistaxis == "percent"){
1484+
tab <- tab/sum(tab)
1485+
}
14721486
barplot(tab, xlab = a, col = histblue)
1487+
}
14731488
}
14741489
}
14751490
})

inst/shiny/ui.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +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."),
512+
selectInput("attrhistaxis",
513+
label = NULL,
514+
choices = c("Barplot: counts" = "count",
515+
"Barplot: percents" = "percent",
516+
"Density plot" = "density")),
508517
uiOutput("attrhistplotspace"))
509518

510519
),

0 commit comments

Comments
 (0)