This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Which are the rows in dt1 that aren't in dt2. | |
which(is.na(dt2[dt1, which=TRUE, mult="first"])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Read head/tail of large files | |
readLines("./2010 BMGF/data/Segments/cell5m_d14.txt", n=10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Export multiple graphs to PNG or SVG at once | |
png("/out/YieldTarget_%d.png") | |
dotplot(cropSPAM~value, | |
plot[!plot$cropSPAM %in% c("BANP", "SUGC"),], | |
group=variable, | |
main=list("Mean GAEZ Low and High Input Yield Potentials \nagainst Mean SPAM Yield", cex=.9), | |
xlab="yield (kg/ha)", | |
pch=c(1,1,3), | |
cex=1.2, | |
col=c("green", "red", "orange"), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Random dot density maps | |
dots.rand <- dotsInPolys(gha, gha@data$total, f="random") | |
plot(dots.rand, | |
pch=19, cex=0.4, col="red", | |
add=TRUE) | |
text(coordinates(gha.reg), | |
labels=gha.reg@data$REGION, | |
adj=c(0, 0), cex=.9, col="black", xpd=NA) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Export circle map to PDF | |
pdf("US04Election-PopBin.pdf") | |
# Draw the USA outline | |
map('usa', fill=T, col="white", bg="darkgray") | |
# Create the colors for the states | |
col <- rep(rgb(.1,.1,.1,.2), length(counties$names)) | |
col[election$order] <- bluered(election$Bush,election$Kerry, .4, graded=F) | |
# Plot states without borders (should work with map, see help for fill | |
# argument, but cannot get it working) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Dissolve map into regions and farming systems | |
gha.fs <- unionSpatialPolygons(gha, interaction(gha@data$REGION, gha@data$FS)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Compute polygon area | |
fs.gha@data$area <- sapply(fs.gha@polygons, slot, "area") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Print for documentation | |
print(ascii(x, | |
align=c("l", "r", "l", "r"), | |
include.rownames=F, | |
frame="topbot", | |
size=NULL), | |
type = "rest") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' This is a simple function for outputting a more advanced | |
#' table than xtable allows. It's aim is to provide the Hmisc | |
#' latex() colgroup and rowgroup functions. | |
#' | |
#' @param x The matrix/data.frame with the data | |
#' @param headings a vector of character strings specifying column | |
#' headings, defaulting to \code{x}'s \code{colnames} | |
#' @param align a character strings specifying column alignments, defaulting to | |
#' \code{paste(rep('c',ncol(x)),collapse='')} to center. | |
#' You may specify \code{align='c|c'} and other LaTeX tabular formatting. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gfmTable <- function(x, ...) { | |
require(ascii) | |
y <- capture.output(print(ascii(x, ...), type="org")) | |
y <- gsub("-+-", "-|-", y, fixed=T) | |
return(writeLines(y)) | |
} |
OlderNewer