Skip to content

Commit

Permalink
Updated vignette
Browse files Browse the repository at this point in the history
  • Loading branch information
cwendorf committed Jan 15, 2022
1 parent db8469e commit 155297f
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 7 deletions.
10 changes: 5 additions & 5 deletions R/polyplot2.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ polyplot2 <- function(x,histogram=FALSE,curve=FALSE,main="PolyPlot2",xlab=NULL,x
if (values) {
labels0 <- round(c(mi,(mi+ma)/2,ma),digits); rR2 <- round((ma-mi)/2,digits);
text(labels0,0,labels0,cex=.8,pos=3,col=col,font=2,offset=1);
mtext('R/2',side=4,at=0,cex=0.8,las=1,col=col,font=2); mtext(rR2,side=4,at=0,cex=0.8,las=1,col=col,font=2,padj=-1.6);
mtext('R/2',side=4,at=0,cex=0.8,las=1,col=col,font=2); mtext(rR2,side=4,at=0,cex=0.8,las=1,col=col,font=2,padj=-1.65);
labels1 <- round(c(xmean-s,xmean,xmean+s),digits); rs <- round(s,digits);
text(labels1,y1,labels1,cex=.8,pos=3,col=col,font=2,offset=1);
mtext('SD',side=4,at=y1,cex=0.8,las=1,col=col,font=2); mtext(rs,side=4,at=y1,cex=0.8,las=1,col=col,font=2,padj=-1.6);
mtext('SD',side=4,at=y1,cex=0.8,las=1,col=col,font=2); mtext(rs,side=4,at=y1,cex=0.8,las=1,col=col,font=2,padj=-1.65);
labels2 <- round(c(m1,xmean,m2),digits); rdelta <- round(delta,digits);
text(labels2,y2,labels2,cex=.8,pos=3,col=col,font=2,offset=1);
mtext('MAD',side=4,at=y2,cex=0.8,las=1,col=col,font=2); mtext(rdelta,side=4,at=y2,cex=0.8,las=1,col=col,font=2,padj=-1.6);
mtext('MAD',side=4,at=y2,cex=0.8,las=1,col=col,font=2); mtext(rdelta,side=4,at=y2,cex=0.8,las=1,col=col,font=2,padj=-1.65);
labels3 <- round(c(q1,xmed,q3),digits); riqr2 <- round(iqr/2,digits);
text(labels3,y3,labels3,cex=.8,pos=3,col=col,font=2,offset=1)
mtext('IQR/2',side=4,at=y3,cex=0.8,las=1,col=col,font=2); mtext(riqr2,side=4,at=y3,cex=0.8,las=1,col=col,font=2,padj=-1.6);
mtext('IQR/2',side=4,at=y3,cex=0.8,las=1,col=col,font=2); mtext(riqr2,side=4,at=y3,cex=0.8,las=1,col=col,font=2,padj=-1.65);
labels4 <- round(mode,digits);
text(labels4,y4,labels4,cex=.8,pos=3,col=col,font=2,offset=1);
mtext('N',side=4,at=y4,cex=0.8,las=1,col=col,font=2); mtext(n,side=4,at=y4,cex=0.8,las=1,col=col,font=2,padj=-1.6);
mtext('N',side=4,at=y4,cex=0.8,las=1,col=col,font=2); mtext(n,side=4,at=y4,cex=0.8,las=1,col=col,font=2,padj=-1.65);
}}

tcol <- function(color,percent=30,name=NULL) {
Expand Down
4 changes: 2 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Scores <- c(rnorm(n=600,mean=100,sd=15),rnorm(n=200,mean=115,sd=20),rnorm(n=200,
polyplot2(Scores)
```

![](polyplot2.jpeg)<!-- -->
![](./figures/polyplot2.jpeg)<!-- -->

By default, the function labels all of the points and provides summary statistics in the margin. Generally speaking, each level/row provides a different category of measures of location and spread.

Expand All @@ -29,6 +29,6 @@ polyplot2(Scores,histogram=TRUE,curve=FALSE,values=FALSE,main="PolyPlot2 plus Hi
polyplot2(Scores,histogram=FALSE,curve=TRUE,values=FALSE,main="PolyPlot2 plus Density Curve",col="darkblue",bg="darkgoldenrod")
```

![](polyplot2plus.jpeg)<!-- -->
![](./figures/polyplot2plus.jpeg)<!-- -->

Further explanation of the polyplot and how it can be used to understand the shape of the distribution is available in Seier and Bonett (2011).
File renamed without changes
File renamed without changes
File renamed without changes
18 changes: 18 additions & 0 deletions docs/scripts/polyplot2tutorial.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# polyplot2
## Tutorial for PolyPlot2

source("http://raw.githubusercontent.com/cwendorf/polyplot2/main/source-polyplot2.R")

### The Basic PolyPlot

#### In order to demonstrate the finer points of a PolyPlot, the following code simulates 1000 scores from a positively skewed unimodal distribution and then calls `polyplot2` using the default options.

Scores <- c(rnorm(n=600,mean=100,sd=15),rnorm(n=200,mean=115,sd=20),rnorm(n=200,mean=130,sd=25))
polyplot2(Scores)

### Using the PolyPlot to Determine Shape

#### The following code demonstrates some of the available options for customizing the PolyPlot.Similarly, it demonstrates how the PolyPlot does a good job of approximating the shape of the underlying distribution.
par(mfrow=c(1,2))
polyplot2(Scores,histogram=TRUE,curve=FALSE,values=FALSE,main="PolyPlot2 plus Histogram",col="darkblue",bg="darkgoldenrod")
polyplot2(Scores,histogram=FALSE,curve=TRUE,values=FALSE,main="PolyPlot2 plus Density Curve",col="darkblue",bg="darkgoldenrod")
58 changes: 58 additions & 0 deletions docs/vignettes/polyplot2tutorial.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
title: "PolyPlot2"
author: "Craig A. Wendorf"
date: "`r Sys.Date()`"
output:
html_document:
toc: true
toc_float: true
toc_depth: 4
collapse: true
theme: cerulean
highlight: tango
keep_md: TRUE
vignette: >
%\VignetteIndexEntry{Tutorial for PolyPlot2}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---

```{r,include=FALSE}
#suppress the warnings and other messages from showing in the knitted file.
knitr::opts_chunk$set(fig.width=7, fig.height=5,fig.path='figures/',echo=TRUE,warning=FALSE,message=FALSE)
```

```{r,include=FALSE}
library(polyplot2)
```

## Tutorial for PolyPlot2

### The Basic PolyPlot

In order to demonstrate the finer points of a PolyPlot, the following code simulates 1000 scores from a positively skewed unimodal distribution and then calls `polyplot2` using the default options.

```{r}
Scores <- c(rnorm(n=600,mean=100,sd=15),rnorm(n=200,mean=115,sd=20),rnorm(n=200,mean=130,sd=25))
polyplot2(Scores)
```

By default, the function labels all of the points and provides summary statistics in the margin. Generally speaking, each level/row provides a different category of measures of location and spread.

- First/Top: Provides the mode of the distribution, with the sample size listed in the right margin
- Second: Provides the quartiles (and median) of the distribution, with the interquartile range divided by 2 in the right margin
- Third: Provides the means of the halves (and the whole) of the distribution, with the mean absolute deviation from the median in the right margin
- Fourth: Provides the mean of the distribution and points +/- one standard deviation from the mean, with the standard deviation in the right margin
- Fifth/Bottom: Provides the range (and midrange) of the distribution, with the range divided by 2 in the right margin

### Using the PolyPlot to Determine Shape

The following code demonstrates some of the available options for customizing the PolyPlot.Similarly, it demonstrates how the PolyPlot does a good job of approximating the shape of the underlying distribution.

```{r}
par(mfrow=c(1,2))
polyplot2(Scores,histogram=TRUE,curve=FALSE,values=FALSE,main="PolyPlot2 plus Histogram",col="darkblue",bg="darkgoldenrod")
polyplot2(Scores,histogram=FALSE,curve=TRUE,values=FALSE,main="PolyPlot2 plus Density Curve",col="darkblue",bg="darkgoldenrod")
```

Further explanation of the polyplot and how it can be used to understand the shape of the distribution is available in Seier and Bonett (2011).

0 comments on commit 155297f

Please sign in to comment.