Saturday, May 17, 2014

Using par,mfrow, cex, pch, rgb , col

I needed complicated graphing to find a way to compare some Geiger-Mueller testing of air filters to understand radioactivity in our local community.  I needed some visual way to compare/contrast "background" or NORML radiation with multiple samples.  The 'par' commands really help here (mfrow, pch, cex) . The data I am plotting with looks like this:


  s1.MicroRads_HR s2.MicroRads_HR s3.MicroRads_HR s4.MicroRads_HR
1            8.47            8.47            8.47            0.00
2            0.00            8.47            0.00            0.00
3            8.47           16.95            0.00            8.47
4            0.00            8.47            8.47            0.00
5           16.95            8.47           16.95            8.47
6           16.95            8.47            8.47            8.47

..

Using the rgb function as input to the 'col' parameter allows me to create custom colors with the first three arguments.

col=rgb(.075,.075,.075,0.25)
col=rgb(.6,.4,.9,0.4)

The fourth argument for 'rgb' is an alpha parameter ('transparency'). By varying the transparency and width ('cex') of the graph tick ('pch'), I was able to nest a transparent and slightly smaller series of circles from the control test inside the sample results.




options(graphics.record=TRUE)
# RMF Media/ RMF Network Security 7:00 PM 3/20/2014. Tested on R 3.03
# Takes four CSV samples (One Control and Two Samples) from Aware Electronics RM-80 GM Counter.
# Configured to read data from "n TBU per line" for any Time Base Unit . I use TBU = 2.
# Samples must have headers with "Time" and "MicroRads_HR" (separated by tab) like this:
# Time MicroRads_HR
# 37264.91529 8.47
# 37264.91531 8.47
# 37264.91534 16.95

# Four Samples
# From Aware-Electronics Manual:
# "MicroRads_HR = microroentgens/hr"
# "One roentgen equals one thousand milliroentgens (1R = 1000mR), and one milliroentgen equals one thousand microroentgens
# (1mR = 1000uR)."

# These files can be found at ftp://rmfmedia.com/web-root/CSV/Data/
 print("Four samples:")
 print("Control is Oreck Desktop Room Filter Fan with Aware Electronics RM80 placed on air exit vent.") 
 print("Sample1 is taken by running RM80 evenly as possible over Oreck 'MAX' room air filtration prefilter/filter while removed from housing.")
 print("Sample2 Tests for hot spots in high (MERV rating) air filter by running RM80 evenly as possible over front and back.  Filter is located outside 8 inch external air intake for one month.")
 print("Sample2 : Both sides of filter tested while filter is encased in plastic freezer sack.")
 print("Sample3 Tests high (MERV rating) air filter located outside 8 inch external air intake for  approximately one month.")
 print("Sample3 : RM80 stationary against center of filter without barrier.")

 s <- read.delim("april_17_2014_RoomFan.csv",header=TRUE,sep="\t")
 b <- read.delim("april_17_2014_Oreck.csv",header=TRUE,sep="\t")
 c <- read.delim("april_17_2014.csv",header=TRUE,sep="\t")
 d <- read.delim("april_17_2014_01.csv",header=TRUE,sep="\t")
 print("Time Base Unit is 2 seconds. MicroRads_HR = microroentgens/hr")
# Select equal amounts of data 
 s <- s[1:174,]
 b <- b[1:174,]
 c <- c[1:174,]
 d <- d[1:174,]

e <- cbind("s1"=s,"s2"=b,"s3"=c,"s4"=d)
e <- e[,c(2,4,6,8)]

par(mfrow=c(2,4))
plot(1:nrow(e) ~ sort(e[,1]),col=rgb(.075,.075,.075,0.25),type="p",cex=3,xlab="MicroRoentgens/HR",ylab="Samples")
title(main="Control")
plot(1:nrow(e) ~ sort(e[,2]), col=rgb(.6,.4,.9,0.4), type="p",cex=4,xlab="MicroRoentgens/HR",ylab="Samples")
title(main="Sample1")
plot(1:nrow(e) ~ sort(e[,3]),col=rgb(.4,.6,.1,0.3),type="p",cex=4,xlab="MicroRoentgens/HR",ylab="Samples")
title(main="Sample2")
plot(1:nrow(e) ~ sort(e[,4]),col=rgb(.2,.8,.9,0.2),type="p",cex=4,xlab="MicroRoentgens/HR",ylab="Samples")
title(main="Sample3")
plot(1:nrow(e) ~ sort(e[,3]),col=rgb(.4,.6,.1,0.3),type="p",cex=4,xlab="MicroRoentgens/HR",ylab="Samples")
points(1:nrow(e) ~ sort(e[,1]), col=rgb(.075,.075,.075,0.25),cex=3)
points(1:nrow(e) ~ sort(e[,2]),col=rgb(.6,.4,.9,0.4),cex=4)
points(1:nrow(e) ~ sort(e[,4]),col=rgb(.2,.8,.9,0.2),cex=4)
title(main="All Samples")
plot(1:nrow(e) ~ sort(e[,2]),col=rgb(.6,.4,.9,0.4),,type="p",cex=4,xlab="MicroRoentgens/HR",ylab="Samples")
points(1:nrow(e) ~ sort(e[,1]), col=rgb(.075,.075,.075,0.25),cex=3)
title(main="Control and Sample 1")
plot(1:nrow(e) ~ sort(e[,3]),col=rgb(.4,.6,.1,0.3),type="p",cex=4,xlab="MicroRoentgens/HR",ylab="Samples")
points(1:nrow(e) ~ sort(e[,1]), col=rgb(.075,.075,.075,0.25),cex=3)
title(main="Control and Sample 2")
plot(1:nrow(e) ~ sort(e[,4]),col=rgb(.2,.8,.9,0.2),type="p",cex=4,xlab="MicroRoentgens/HR",ylab="Samples")
points(1:nrow(e) ~ sort(e[,1]), col=rgb(.075,.075,.075,0.25),cex=3)
title(main="Control and Sample 3")
mtext("X axis = MicroRoentgens/HR Y axis = 174 Samples",side=1, outer=TRUE,line=-1)

No comments:

Post a Comment