Giter Site home page Giter Site logo

Improve age pyramid about sitrep HOT 13 CLOSED

r4epi avatar r4epi commented on June 15, 2024
Improve age pyramid

from sitrep.

Comments (13)

dirkschumacher avatar dirkschumacher commented on June 15, 2024 1

Ok. Just a assume the code works perfectly in the template. I can improve it :)

from sitrep.

zkamvar avatar zkamvar commented on June 15, 2024 1

BLAM!

library("epireports")
set.seed(2018-01-15)
ages <- cut(sample(80, 150, replace = TRUE),
           breaks = c(0, 5, 10, 30, 50, 80, 100), right = FALSE)
sex  <- sample(c("Female", "Male"), 150, replace = TRUE)
ill  <- sample(0:1, 150, replace = TRUE)
dat  <- data.frame(AGE = ages, sex = sex, ill = ill, stringsAsFactors = FALSE)
datd <- dat[dat$AGE != levels(dat$AGE)[2], , drop = FALSE]
print(ap3 <- plot_age_pyramid(datd, age_group = "AGE"))
#> Warning: Removed 1 rows containing missing values (position_stack).

ap3$data
#> # A tibble: 10 x 4
#> # Groups:   AGE [6]
#>    AGE      sex        n .group
#>    <fct>    <chr>  <int>  <int>
#>  1 [0,5)    Female    -3      1
#>  2 [0,5)    Male       3      1
#>  3 [5,10)   <NA>      NA      2
#>  4 [10,30)  Female   -22      3
#>  5 [10,30)  Male      27      3
#>  6 [30,50)  Female   -16      4
#>  7 [30,50)  Male      19      4
#>  8 [50,80)  Female   -24      5
#>  9 [50,80)  Male      25      5
#> 10 [80,100) Female    -4      6

Created on 2019-01-15 by the reprex package (v0.2.1)

from sitrep.

aspina7 avatar aspina7 commented on June 15, 2024

So dplyr apparently doesnt include factor levels with zero counts, must be some workaround but a quick google got me no-where. So say you have an over 80 age group and theres none in there - plot_age_pyramid will just show the group below that max age.

from sitrep.

aspina7 avatar aspina7 commented on June 15, 2024

Age pyramid works well - the issue of not including NA groups still there though (see two comments above). May also be good to include an option to change text size? @zkamvar

from sitrep.

dirkschumacher avatar dirkschumacher commented on June 15, 2024

The age pyramid code needs to be extended such that you can choose arbitrary groups for coloring. Currently it is by sex, but I have also seen by case definition

from sitrep.

dirkschumacher avatar dirkschumacher commented on June 15, 2024

@zkamvar is this something you can take a look at?

from sitrep.

zkamvar avatar zkamvar commented on June 15, 2024

ja!

from sitrep.

zkamvar avatar zkamvar commented on June 15, 2024

Age pyramid works well - the issue of not including NA groups still there though (see two comments above). May also be good to include an option to change text size? @zkamvar

I was able to get the NA groups to show up, though. Is it desireable to get something else?

library("epireports")
set.seed(2018-01-15)
ages <- cut(sample(80, 150, replace = TRUE),
            breaks = c(0, 5, 10, 30, 70), right = FALSE)
sex  <- sample(c("Female", "Male"), 150, replace = TRUE)
ill  <- sample(0:1, 150, replace = TRUE)
dat  <- data.frame(AGE = ages, sex = sex, ill = ill, stringsAsFactors = FALSE)
print(ap   <- plot_age_pyramid(dat, age_group = "AGE"))

print(ap   <- plot_age_pyramid(dat, age_group = "AGE", split_by = "ill"))

Created on 2019-01-15 by the reprex package (v0.2.1)

from sitrep.

aspina7 avatar aspina7 commented on June 15, 2024

ah nice!
And what if there is a factor level with zero counts? Cus I couldnt get that to work either....

from sitrep.

zkamvar avatar zkamvar commented on June 15, 2024

Ah! Still can't do that, but I'll see if I can give it a go

from sitrep.

dirkschumacher avatar dirkschumacher commented on June 15, 2024

Looks like it is good for now?

from sitrep.

aspina7 avatar aspina7 commented on June 15, 2024

Yep perfect!
Will eventually tinker with some aesthetic stuff like being able to not show the y-axis line. Showing horizontal dashed lines at each group and being able to mess with text size.
But for now is great as is

from sitrep.

dirkschumacher avatar dirkschumacher commented on June 15, 2024

I will close it. Feel free to open a new issue for specific things

from sitrep.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.