Help! I want to get rid of the red significant asterisks!
I have highlighted the areas in the source code in yellow that I have been trying to manipulate to remove them but with no luck - I just mess everything up!
##Source Code
#' correlation matrix chart
#'
#' Visualization of a Correlation Matrix. On top the (absolute) value of the
#' correlation plus the result of the cor.test as stars. On bottom, the
#' bivariate scatterplots, with a fitted line
#'
#'
#' @param R data for the x axis, can take matrix,vector, or timeseries
#' @param histogram TRUE/FALSE whether or not to display a histogram
#' @param method a character string indicating which correlation coefficient
#' (or covariance) is to be computed. One of "pearson"
#' (default), "kendall", or "spearman", can be abbreviated.
#' @param \dots any other passthru parameters into \code{\link{pairs}}
#' @note based on plot at
#' \url{http://addictedtor.free.fr/graphiques/sources/source_137.R}
#' @author Peter Carl
#' @seealso \code{\link{table.Correlation}}
###keywords ts multivariate distribution models hplot
#' @examples
#'
#' data(managers)
#' chart.Correlation(managers[,1:8], histogram=TRUE, pch="+")
#'
#' @export
chart.Correlation <-
function (R, histogram = TRUE, method=c("pearson", "kendall", "spearman"), ...)
{ # @author R Development Core Team
# @author modified by Peter Carl
# Visualization of a Correlation Matrix. On top the (absolute) value of the
# correlation plus the result of the cor.test as stars. On botttom, the
# bivariate scatterplots, with a fitted line
x = checkData(R, method="matrix")
if(missing(method)) method=method[1] #only use one
# Published at http://addictedtor.free.fr/graphiques/sources/source_137.R
panel.cor <- function(x, y, digits=2, prefix="", use="pairwise.complete.obs", method, cex.cor, ...)
{
usr <- par("usr"); on.exit(par(usr))
par(usr = c(0, 1, 0, 1))
r <- cor(x, y, use=use, method=method) # MG: remove abs here
txt <- format(c(r, 0.123456789), digits=digits)[1]
txt <- paste(prefix, txt, sep="")
if(missing(cex.cor)) cex <- 0.8/strwidth(txt)
test <- cor.test(x,y, method=method)
# borrowed from printCoefmat
Signif <- symnum(test$p.value, corr = FALSE, na = FALSE,
cutpoints = c(0, 0.001, 0.01, 0.05, 0.1, 1),
symbols = c("***", "**", "*", ".", " "))
# MG: add abs here and also include a 30% buffer for small numbers
text(0.5, 0.5, txt, cex = cex * (abs(r) + .3) / 1.3)
text(.8, .8, Signif, cex=cex, col=2)
}
f <- function(t) {
dnorm(t, mean=mean(x), sd=sd.xts(x) )
}
hist.panel = function (x, ...) {
par(new = TRUE)
hist(x,
col = "light gray",
probability = TRUE,
axes = FALSE,
main = "",
breaks = "FD")
lines(density(x, na.rm=TRUE),
col = "red",
lwd = 1)
#lines(f, col="blue", lwd=1, lty=1) how to add gaussian normal overlay?
rug(x)
}
# Draw the chart
if(histogram)
pairs(x, gap=0, lower.panel=panel.smooth, upper.panel=panel.cor, diag.panel=hist.panel, method=method, ...)
else
pairs(x, gap=0, lower.panel=panel.smooth, upper.panel=panel.cor, method=method, ...)
}
##Plotting my data to chart.correlation
## Correlation matrix with p-values. See http://goo.gl/nahmV for documentation of this function
cor.prob <- function (X, dfr = nrow(X) - 2) {
R <- cor(X, use="pairwise.complete.obs")
above <- row(R) < col(R)
r2 <- R[above]^2
Fstat <- r2 * dfr/(1 - r2)
R[above] <- 1 - pf(Fstat, 1, dfr)
R[row(R) == col(R)] <- NA
R
}
## Use this to dump the cor.prob output to a 4 column matrix
## with row/column indices, correlation, and p-value.
## See StackOverflow question: http://goo.gl/fCUcQ
flattenSquareMatrix <- function(m) {
if( (class(m) != "matrix") | (nrow(m) != ncol(m))) stop("Must be a square matrix.")
if(!identical(rownames(m), colnames(m))) stop("Row and column names must be equal.")
ut <- upper.tri(m)
data.frame(i = rownames(m)[row(m)[ut]],
j = rownames(m)[col(m)[ut]],
cor=t(m)[ut],
p=m[ut])
}
## get the CRG biomass data
##Mydata
Crgdata = read.table("C:/ CRGbiomassteena_redo1.txt", header=TRUE)
## use the path that your data file is located at
## In order to see if R is reading datacrgdata
crgdata
## You should see your data
# correlation matrix
cor(crgdata)
# correlation matrix with p-values
cor.prob(crgdata)
# "flatten" that table
flattenSquareMatrix(cor.prob(crgdata))
# plot the data
chart.Correlation(crgdata)
--
Check out our R resources at http://www.noamross.net/davis-r-users-group.html
---
You received this message because you are subscribed to the Google Groups "Davis R Users' Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to davis-rug+...@googlegroups.com.
Visit this group at http://groups.google.com/group/davis-rug.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to a topic in the Google Groups "Davis R Users' Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/davis-rug/MUL7rEEZdac/unsubscribe.
To unsubscribe from this group and all its topics, send an email to davis-rug+...@googlegroups.com.
Visit this group at http://groups.google.com/group/davis-rug.
For more options, visit https://groups.google.com/d/optout.
--
Check out our R resources at http://www.noamross.net/davis-r-users-group.html
---
You received this message because you are subscribed to a topic in the Google Groups "Davis R Users' Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/davis-rug/MUL7rEEZdac/unsubscribe.
To unsubscribe from this group and all its topics, send an email to davis-rug+...@googlegroups.com.
Visit this group at http://groups.google.com/group/davis-rug.
For more options, visit https://groups.google.com/d/optout.
pdf("crgscatter.pdf", par(family="Times"))
plot(chart.Correlation(crgdata))
dev.off()
does not work
--
Check out our R resources at http://www.noamross.net/davis-r-users-group.html
---
You received this message because you are subscribed to a topic in the Google Groups "Davis R Users' Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/davis-rug/MUL7rEEZdac/unsubscribe.
To unsubscribe from this group and all its topics, send an email to davis-rug+...@googlegroups.com.
Visit this group at http://groups.google.com/group/davis-rug.
For more options, visit https://groups.google.com/d/optout.
Those are the correct commands. Just make sure the pdf line happens before any of the plotting and dev.off line happens at the very end. typing "getwd()" (no quotes) into the R prompt will tell you what directory the PDF went to.
--
You received this message because you are subscribed to the Google Groups "Davis R Users' Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to davis-rug+...@googlegroups.com.
Visit this group at http://groups.google.com/group/davis-rug.
For more options, visit https://groups.google.com/d/optout.