lattice

Scoping in custom lattice functions (group argument)

心不动则不痛 提交于 2019-12-18 07:09:00
问题 Please consider this function: tf <- function(formula = NULL, data = NULL, groups = NULL) { grv <- eval(substitute(groups), data, environment(formula)) # the values grn <- as.character(match.call()$groups) # the name gr <- match.call()$groups # unquoted name p <- xyplot(formula, data, # draws the data but not in groups # Try these options: # p <- xyplot(formula, data, groups, # can't find 'cat2' # p <- xyplot(formula, data, groups = data[,grn], # can't fine grn # p <- xyplot(formula, data,

R plot grid value on maps

拥有回忆 提交于 2019-12-18 04:27:26
问题 I have several file with the following format: lat,lon,value. I would like to plot a colored grid map with such value for each one of the lat,lon point and overlapping it over the EU map. Thanks for support. 回答1: There are roughly two options: one using the lattice and sp package and the other using the ggplot2 package: lattice / sp First you have to transform your data to a SpatialPixelsDataFrame (provided by the sp-package), assuming your data is called df : require(sp) gridded(df) = c("lat

creating a more continuous color palette in r, ggplot2, lattice, or latticeExtra

独自空忆成欢 提交于 2019-12-18 04:13:02
问题 Warning.... very novice question follows: I am trying to plot a fairly regular distribution of several thousand (X,Y) points each associated with a value, let's call Z, which varies very irregularly between, say, -20 to +20. I am not interested in smoothing; I want the point Z values to plot according to a smoothly varying color palette much like Gnuplot can do with the proper smooth color palette. I've tried base R, ggplot2, and latticeExtra, and as best I can, I can come up with the

How to change the order of the panels in simple Lattice graphs

℡╲_俬逩灬. 提交于 2019-12-18 03:30:09
问题 Hi I am using the following code to generate an xyplot using lattice xyplot(Rate~Weight|Temp, groups=Week, rate, pch=c(15,16,17,3), col=c("blue","red","green","purple"), as.table=TRUE, xlab="Weight (gr)", ylab="Rate (umol/L*gr)", main="All individuals and Treatments at all times", strip=strip.custom(strip.names=1), key= list(text=list(c("Week","1","2","6","8")), points=list(pch=c(NA,15,16,17,3),col=c(NA,"blue","red","green","purple")), space="right") ) This gives me the following plot: Now

display values in stacked lattice barchart

依然范特西╮ 提交于 2019-12-18 02:46:26
问题 I want to display the values of a 100% bar for each part of it. Unfortunately I don't know how to do it. The graph should be in lattice because of the legend position (I tried it with ggplot2, but you can't show the legend in one row). I'm pleased about any suggestions or ideas. library(lattice) data(postdoc, package = "latticeExtra") colnames(postdoc) <- c("Legendtext 1", "2", "3", "4", "5") colorset <- simpleTheme(col = c(rgb(166,27,30,maxColorValue = 255), rgb(192,80,77,maxColorValue = 255

How to add boxplots to scatterplot with jitter

老子叫甜甜 提交于 2019-12-17 17:36:17
问题 I am using following commands to produce a scatterplot with jitter: ddf = data.frame(NUMS = rnorm(500), GRP = sample(LETTERS[1:5],500,replace=T)) library(lattice) stripplot(NUMS~GRP,data=ddf, jitter.data=T) I want to add boxplots over these points (one for every group). I tried searching but I am not able to find code plotting all points (and not just outliers) and with jitter. How can I solve this. Thanks for your help. 回答1: Here's one way using base graphics. boxplot(NUMS ~ GRP, data = ddf,

How to make a ggplot2 contour plot analogue to lattice:filled.contour()?

蓝咒 提交于 2019-12-17 16:18:11
问题 I've been learning ggplot2, and hope to use it for all my R graphing. However, I've yet to find a way to make a contour plot that looks analogous to a conventional contour plot, like what can be obtained using lattice:filled.contour(). For example: #define data x<-seq(1,11,1) y<-seq(1,11,1) xyz.func<-function(x,y) {-10.4+6.53*x+6.53*y-0.167*x^2-0.167*y^2+0.0500*x*y} #contour plot using lattice graphics and R Color Brewer library(lattice) #for filled.contour() library(RColorBrewer) #for brewer

How to save a plot as image on the disk?

痴心易碎 提交于 2019-12-16 20:05:42
问题 I plot a simple linear regression using R. I would like to save that image as PNG or JPEG, is it possible to do it automatically? (via code) There are two different questions: First, I am already looking at the plot on my monitor and I would like to save it as is. Second, I have not yet generated the plot, but I would like to directly save it to disk when I execute my plotting code. 回答1: There are two closely-related questions, and an answer for each. 1. An image will be generated in future

How to plot Bayesian prior and posterior distributions in one panel using R?

限于喜欢 提交于 2019-12-14 03:48:39
问题 I've tried several approaches, including qqmath , lattice densityplot() and a number of panel functions like panel.mathdensity and panel.densityplot . However, I couldn't get them to do what I want them to do. An internet search on this topic produces results which focus either on base plots in R or don't draw both distributions in one panel. I could use R base graphics, however, I also want to plot several distribution pairs and one panel for each pair. The books "RGraphics" and "Lattice:

Formatting axis labels in lattice plot

↘锁芯ラ 提交于 2019-12-14 03:48:15
问题 How can I change the y-axis labels format to usual ( xxx.xxx ) instead of scientific, in the following plot? df <- read.table(textConnection(" ypogr_act amount cumSum 2012-09-20 30.00 30.00 2012-11-19 1834.69 1864.69 2012-11-30 2915.88 4780.57 2012-11-30 2214.98 6995.55 2012-12-18 21815.00 28810.55 2012-12-19 315000.00 343810.55 2012-12-21 1050.00 344860.55 2012-12-28 1300.00 346160.55 2013-01-10 1836.77 347997.32 2013-01-17 122193.00 470190.32 2013-03-22 415000.00 885190.32 ")->con,header=T)