Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recommendations #19

Closed
Jadamso opened this issue Mar 14, 2024 · 2 comments
Closed

Recommendations #19

Jadamso opened this issue Mar 14, 2024 · 2 comments
Assignees

Comments

@Jadamso
Copy link
Contributor

Jadamso commented Mar 14, 2024

To compare multiple groups of histogram densities, it helps to adjust the wex. Here is a MWE that does so, which you may want to add to a vignette.

dlist1 <- lapply(c(10,20,30,40), function(n) runif(n))
dlist2 <- lapply(c(100,200,300,400), function(n) runif(n))

hscale1 <- sapply(dlist1, function(r){
    max(hist(r, plot=F, breaks=seq(0,1,by=.05))$density)})
histoplot(dlist1, side='left', col=grey(.3),
    breaks=seq(0,1,by=.05), add=F, pchMed=NA, drawRect=F, border=NA,
    wex=hscale1/length(hscale1))

hscale2 <- sapply(dlist2, function(r){
    max(hist(r, plot=F, breaks=seq(0,1,by=.05))$density)})
histoplot(dlist2, side='right', col=grey(.7),
    breaks=seq(0,1,by=.05), add=T, pchMed=NA, drawRect=F, border=NA,
    wex=hscale2/length(hscale2))

Sometimes, it is helpful to see the raw counts instead.

dvec <- length(unlist(c(dlist1, dlist2)))/4

histoplot(dlist1, side='left', col=grey(.3),
    breaks=seq(0,1,by=.05), add=F, pchMed=NA, drawRect=F, border=NA,
    wex=sapply(dlist1, length)/dvec*hscale1/length(hscale1))
histoplot(dlist2, side='right', col=grey(.7),
    breaks=seq(0,1,by=.05), add=T, pchMed=NA, drawRect=F, border=NA,
    wex=sapply(dlist2, length)/dvec*hscale2/length(hscale2))

It may also benefit some users to pass density and angle arguments to the histograms (ultimately rect) and create outer legends

hist(runif(100), density=c(10,20), angle=c(22,90+22) ,col=1)

outer_legend <- function(...) {
  opar <- par(fig=c(0, 1, 0, 1), oma=c(0, 0, 0, 0), mar=c(0, 0, 0, 0), new=T)
  on.exit(par(opar))
  plot(0, 0, type='n', bty='n', xaxt='n', yaxt='n')
  legend(...)
}
outer_legend('topright', pch=15, density=c(10,20), angle=c(22,90+22), col=0, legend=c('Y','N'))
@TomKellyGenetics
Copy link
Owner

I've added this to the examples for histoplot (with minor modifications to pass updated CRAN checks). For now I've not updated the vignettes but this is a great suggestion.

@TomKellyGenetics
Copy link
Owner

Release v0.5.0 submitted to CRAN closes #19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants