r - Plot multiple sparkles by overlapping each other -


i use following code make plot first set of values (here number of crimes).

this have now: my sparkline single set of data

here code use plot it:

library(lattice) library(latticeextra) library(grid) library(reshape) library(rcurl) dd <- read.csv(text = geturl("https://gist.githubusercontent.com/geekonacid/da022affd36310c96cd4/raw/9c2ac2b033979fcf14a8d9b2e3e390a4bcc6f0e3/us_nr_of_crimes_1960_2014.csv")) d <- melt(dd, id="year") names(d)[1] <- "time" pdf("sparklines_lattice_multiple_ten.pdf", height=10, width=8) xyplot(value~time | variable, d, xlab="", ylab="", strip=f, lwd=0.7, col=1, type="l",         layout=c(1,length(unique(d$variable))), between = list(y = 1),        scales=list(y=list(at=null, relation="free"), x=list(fontfamily="serif")),         par.settings = list(axis.line = list(col = "transparent"),                            layout.widths=list(right.padding=20, left.padding=-5)),        panel = function(x, y, ...) {          panel.xyplot(x, y, ...)          pushviewport(viewport(xscale=current.viewport()$xscale-5,                                 yscale=current.viewport()$yscale, clip="off"))          panel.text(x=tail(x,n=1), y=tail(y,n=1), labels=levels(d$variable)[panel.number()],                      fontfamily="serif", pos=4)          popviewport()          panel.text(x=x[which.max(y)], y=max(y), labels=round(max(y),0), cex=0.8,                     fontfamily="serif",adj=c(0.5,2.5))          panel.text(x=x[which.min(y)], y=min(y), labels=round(min(y),0), cex=0.8,                     fontfamily="serif",adj=c(0.5,-1.5))          panel.text(x=tail(x,n=1), y=tail(y,n=1), labels=round(tail(y,n=1),0), cex=0.8,                     fontfamily="serif", pos=4)          panel.points(x[which.max(y)], max(y),  pch=16, cex=1)          panel.points(x[which.min(y)], min(y),  pch=16, cex=1, col="red")}) dev.off() 

what need: add dimension (i.e., line) each sparkline number of suspects per each type of crime (e.g., vehicle.theft, larceny.theft, etc.). in other words, i want add line each sparkline compare dynamics of (1) number of crimes , (2) number of suspect each type of crime.

to clear: i want set 2 lines each sparkline.

just before answer question please aware of:

  1. par(new=true) doesn't work: warning message: in par(new = true) : calling par(new=true) no plot. creates 2 separated pages in pdf file 2 different sparklines. need opposite result: two sparklines on same pdf page.

thank efforts me (if so).


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -