[R-sig-Geo] My code mistakenly prints multiple PDF pages

Jim Burke javajimburke at gmail.com
Sun Sep 4 20:24:13 CEST 2016


The code below should print ONE page but instead prints its different plots
on THREE pages
Please take a look and let me know my mistake. I appreciate any and all
insight.

tmpPDFName = paste("HD_", shp$LD,"_African_American", ".pdf", sep = "",
collapse = NULL)
pdf(file = tmpPDFName,
      width=8.5, height=10, onefile=TRUE, family="Helvetica",
      paper="a4r", encoding= "default",
      bg="transparent", fg="black", pointsize=16, pagecentre=TRUE,
colormodel="srgb",
      useDingbats=TRUE, useKerning=TRUE, fillOddEven=FALSE, compres=TRUE)

# CENSUS BLOCKS
HD_census$Black[is.na(HD_census$Black)] <- 0
HD_census$Total[is.na(HD_census$Total)] <- 0
add.alpha(brewer.pal(5,'Reds'),0.5)
my_shades <- auto.shading( ifelse(HD_census$Total==0, 0,
(HD_census$Black/HD_census$Total)/100 ), n = 5, cutter = rangeCuts, cols =
brewer.pal(5, "Reds"))
GISTools::choropleth(HD_census, ifelse(HD_census$Total==0, 0,
(HD_census$Black/HD_census$Total)/100 ),
   shading = my_shades, border="transparent")
title(main = "Africian American Percentages", col = "red", font = 3)   #
Horizontal HD114

# POLYGON OUTLINE
#plot.new()
#par(new=TRUE)
plot (shp, add=FALSE, lwd = 4, border='green' )

# POLYGON OUTLINE TITLES
MyTitle <- paste('House District', shp$LD, shp$Candidate, shp$HD_Phone,
sep="\n")

# POLYGON OUTLINE Insert date and time label. At lower left corner.
today <- Sys.Date()
str_today <- format(Sys.time(),"%m/%d/%Y %I:%M %p")
str_text <- paste("Created:", str_today, sep=" ")
##  "usr" returns a vector containing xleft, xright, ybottom, ytop.
usr <- par( "usr" )
text( usr[ 1 ], usr[ 3 ], str_text,  adj = c( 0, 0 ), col = 'darkgreen',
cex=.9 )

# PLOT PRECINCTS INSIDE LARGER POLYGON
plot (HD_Precincts, add=FALSE, lwd = 2, border='blue' )

myLabel <- paste( bquote(.(HD_Precincts$PCT)),
bquote(.(HD_Precincts$First_Name)),
bquote(.        (HD_Precincts$Last_Name)), bquote(.(HD_Precincts$Phone)),
 sep = '\n', collapse = NULL)
# PLOT PRECINCT LABELS
HDShp_LatLong <- polygonsLabel(HD_Precincts,
   labels = myLabel, method = c("maxdist",
   "buffer", "centroid", "random", "inpolygon")[2],
   gridpoints = 60, polypart = c("all","largest")[2],
   cex = .4, col="blue", doPlot = TRUE)
# Close and write to PDF
dev.off()

Thanks,
Jim

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list