[R] Can't Get Lattice Histogram Minor Tick Marks to Work
Donald Macnaughton
donm@c @end|ng |rom m@t@t@t@com
Wed Apr 25 06:12:38 CEST 2018
Thanks Jeff,
I attached a file with the program to my earlier email because the posting guide seemed to imply that non-binary attachments would work. But I see that the file was stripped off.
I installed the program file on a web site, but when I downloaded it, the line breaks were stripped out. So I've included the program below:
-------------------------------------------------------
# This R program illustrates a problem with the histogram function in
# the lattice package.
# This program requires the latticeExtra package to be installed to
# generate the minor tickmarks.
library(lattice)
library(latticeExtra)
# First, please run the program to see the problem.
# Note how the histogram shows minor tickmarks on the vertical axis.
# I would like to show only a SINGLE minor tickmark between major tickmarks on
# the vertical axis, which helps to show the viewer that all the bars
# in the left panel are at five percent.
# The yscale.components.subticks function in the latticeExtras package
# has arguments to contol the minor tickmarks, but I can't get them to work.
# How can a get a single minor tickmark between the major tickmarks on
# the vertical axis?
# Thanks for your help,
# Don Macnaughton donmac using matstat.com
# Generate data in an 20 x 2 matrix for left panel. In my real application
# the data file contains many more rows, but that's not necessary here.
for (i in 1:20) {
if (i == 1) {pmat = c(0.045,0)} else {
pmat = rbind(pmat,c(i*0.05-0.001,0))}
}
# Generate data for the right panel in the same matrix.
counts = c(90, 12.5, 9, 8, 7, 6.5, 6, 5.5, 5, 4.5,
4, 3.5, 3, 2.8, 2.2, 2, 1.8, 1.6, 1.4, 1.0)
for (i in 1:20) {
maxCount = 100 * counts[i]
for (j in 1:maxCount){
pmat = rbind( pmat, c(i*0.05-0.001,2) )
}
}
# Convert the matrix to a data frame and add column names.
pDat = data.frame(pmat)
colnames(pDat) = c("pValue","nonCent")
# Create a factor to enable titles on the two panels.
nonCent.f = factor(pDat$nonCent,
labels=c("Noncentrality = 0.0", "Noncentrality = 2.0"))
# Use the lattice histogram function to draw the histogram.
histogram( ~ pValue | nonCent.f, data = pDat, nint = 20,
endpoints = c(0, 1), layout = c(2,1),
yscale.components=yscale.components.subticks,
scales=list(alternating=FALSE,tck=c(1,0)),
col="lightgray")
-------------------------------------------------------
Don Macnaughton
-----Original Message-----
From: Jeff Newmiller <jdnewmil using dcn.davis.ca.us>
Sent: Tuesday, April 24, 2018 11:28 PM
To: r-help using r-project.org; Donald Macnaughton <donmac using matstat.com>; R-Help <R-help using r-project.org>
Subject: Re: [R] Can't Get Lattice Histogram Minor Tick Marks to Work
Per the Posting Guide, why didn't you post the reproducible R code example?
On April 24, 2018 8:22:15 PM PDT, Donald Macnaughton <donmac using matstat.com> wrote:
>I'm drawing a paneled histogram using the lattice package. I've
>succeeded in adding minor tick marks to the vertical axis, but I can't
>get the desired number of minor tick marks between the major tick
>marks.
>
>I've attached a self-contained program to illustrate the problem.
>
>Thanks for your help,
>
>Don Macnaughton
>
>
>Here's my sessionInfo:
>
>R version 3.4.3 (2017-11-30)
>Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64
>(build 16299)
>
>Matrix products: default
>
>locale:
>[1] LC_COLLATE=English_United States.1252
>[2] LC_CTYPE=English_United States.1252
>[3] LC_MONETARY=English_United States.1252
>[4] LC_NUMERIC=C
>[5] LC_TIME=English_United States.1252
>
>attached base packages:
>[1] graphics grDevices utils datasets stats methods base
>
>
>other attached packages:
>[1] psych_1.7.8 latticeExtra_0.6-28 RColorBrewer_1.1-2
>[4] Hmisc_4.0-3 ggplot2_2.2.1 Formula_1.2-2
>[7] survival_2.41-3 lattice_0.20-35
>
>loaded via a namespace (and not attached):
> [1] Rcpp_0.12.14 pillar_1.0.1 compiler_3.4.3
> [4] plyr_1.8.4 base64enc_0.1-3 tools_3.4.3
> [7] rpart_4.1-11 digest_0.6.13 nlme_3.1-131
>[10] tibble_1.4.1 gtable_0.2.0 checkmate_1.8.5
>[13] htmlTable_1.11.1 rlang_0.1.6 Matrix_1.2-12
>[16] rstudioapi_0.7 parallel_3.4.3 gridExtra_2.3
>[19] stringr_1.2.0 cluster_2.0.6 knitr_1.18
>[22] htmlwidgets_0.9 grid_3.4.3 nnet_7.3-12
>[25] data.table_1.10.4-3 foreign_0.8-69 magrittr_1.5
>[28] backports_1.1.2 scales_0.5.0 htmltools_0.3.6
>[31] splines_3.4.3 mnormt_1.5-5 colorspace_1.3-2
>[34] stringi_1.1.6 acepack_1.4.1 lazyeval_0.2.1
>[37] munsell_0.4.3
>______________________________________________
>R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.
--
Sent from my phone. Please excuse my brevity.
More information about the R-help
mailing list