lattice

Add text to lattice plot?

余生长醉 提交于 2019-12-07 21:48:50
问题 Could someone tell me how to add a text line to lattice plot. My code is: xyplot(Neff~Eeff,data=phuong,panel=mypanel, col="black", pch=18,xlab="Energy efficiency (%)", ylab = "Nitrogen efficiency (%)", main="(a)") Here pane=mypanel is to add an abline. I want to add a linear regression equation between Eeff and Neff to their plot. Thanks! 回答1: So, with reproducible data: set.seed(1) phuong <- data.frame(Eeff = rnorm(100,31)) phuong$Neff <- rnorm(100,19.7 + .36*phuong$Eeff) # Create the lm

Vertical box-percentile plot with Lattice & panel.bpplot

自作多情 提交于 2019-12-07 19:09:12
问题 I am drawing box-percentile plots in R, using the box-percentile panel function from Hmisc ( panel.bpplot ) with bwplot from lattice . I have a numeric vector ( Length ), and would like to show its distribution across the levels of a factor variable ( Month ). Here's an example with fake data: For example, set.seed(13) Length<-sample(1:10, 1000, replace=TRUE) Month<-sample(c("Apr","May","Jul","Aug","Sep","Nov"), 1000, replace=TRUE) df<-cbind(Month, Length) df<-as.data.frame(df) df$Month<

How do I extract ecdf values out of ecdfplot()

狂风中的少年 提交于 2019-12-07 14:21:20
问题 If I use the ecdfplot() function of the latticeExtra package how do I get the actual values calculated i.e. the y-values which correspond to the ~x|g input? I've been looking at ?ecdfplot but there's not discription to it. For the usual highlevel function ecdf() it works with the command plot=FALSE but this does not work for ecdfplot() . The reason I want to use ecdfplot() rather than ecdf() is that I need to calculate the ecdf() values for a grouping variable. I know I could do this handish

R lattice bar chart: specify colour of legend?

风流意气都作罢 提交于 2019-12-07 13:51:22
问题 My data looks like this: service,rating_1,rating_2,rating_3,rating_4,rating_5 renew_patent,0,0,1,2,11 apply_benefit,21,20,121,828,1744 apply_employment_tribunal,0,0,0,0,0 I want R to print me a histogram for each row, with the columns as the bars of the histogram. I've got this so far: require(lattice) data <- read.csv("test.csv", header = TRUE) colors = c('red', 'orange', 'yellow', 'blue', 'green') barchart(rating_1+rating_2+rating_3+rating_4+rating_5 ~ service, data=data, auto.key=list

Add different unique labels to each panel in lattice

大兔子大兔子 提交于 2019-12-07 13:24:13
问题 It's quite clear How to label panels in lattice using panel.text or ltext arguments. However, what if I want to use a different, unique label for each panel in lattice? Let me illustrate my point with this simplified Dotplot : library(Hmisc) #example data data <- data.frame(transport=rep(c("bicycle","bus"),each=2), att=rep(c("behaviour control","intention"),2), value=c(4.134,4.5,3.77,2.4), Lo=c(3.92,4.37,3.51,2.2), Hi=c(4.34,4.62,4.02,2.61)) #labels I want to use labels.hi=c("likely","easy")

Decrease number of x-axis ticks (labels) in barchart

旧时模样 提交于 2019-12-07 05:04:18
问题 I am using barchart from the lattice package. I have time series data going back 10 years, and I would like the x-axis to be displayed in the format %b-%Y, in six month intervals. This is trivially accomplished in xyplot (given vector of dates DateVector) with syntax such as: scales=list(x=list(format = "%b-%Y",tick.number = length(DateVector)/2)) barchart ignores the tick.number option for factors by design, however, so the x axis becomes unreadable for large number of data labels. How can I

How to plot a sparse (with gaps) line with its segments colored according to some factor in R?

狂风中的少年 提交于 2019-12-07 04:50:01
问题 I have a data.frame with time series. There are also NA s in it as well as there is a factor that I'd like to use to highlight different segments of a line. flow.mndnr <- function(id, start, end) { uri <- sprintf("http://maps1.dnr.state.mn.us/cgi-bin/csg.pl?mode=dump_hydro_data_as_csv&site=%s&startdate=%s&enddate=%s", id, start, end) dat <- read.csv(url(uri), colClasses=c(Timestamp="Date")) rng <- range(dat$Timestamp) d <- data.frame(Timestamp=seq(rng[1], rng[2], by='day')) merge(d, dat, all

xyplot time series with positive values in green, negative in red, in R

落爺英雄遲暮 提交于 2019-12-07 02:22:41
问题 Is there a neat way to color negative values in red and others in green for a (simplified) time series plot below, using lattice::xyplot ? set.seed(0) xyplot(zoo(cumsum(rnorm(100))), grid=T) 回答1: Lattice is based on grid so you can use grid's clipping functionality library(lattice) library(grid) set.seed(0) x <- zoo(cumsum(rnorm(100))) xyplot(x, grid=TRUE, panel = function(x, y, ...){ panel.xyplot(x, y, col="red", ...) grid.clip(y=unit(0,"native"),just=c("bottom")) panel.xyplot(x, y, col=

Add a line to coplot {graphics}, classic approaches don't work

六眼飞鱼酱① 提交于 2019-12-06 16:33:24
I found coplot {graphics} very useful for my plots. However, I would like to include there not only one line, but add there one another. For basic graphic I just need to add = TRUE to add another line, or tu use plot(..) and lines(..). For {lattice} I can save my plots as objects a<-xyplot(..) b<-xyplot(..) and display it simply by a + as.layer(b) . No one of these approaches works for coplot() , apparently because creating objects as a<-coplot() doesn't produce trellis graphic but NULL object. Please, any help how to add data line in coplot()? I really like its graphic so I wish to keep it.

Saving Lattice Plots with RInside and Rcpp

萝らか妹 提交于 2019-12-06 15:04:51
I am trying to build an R application in C++ using RInside. I wanted to save the plots as images in specified directory using codes, png(filename = "filename", width = 600, height = 400) xyplot(data ~ year | segment, data = dataset, layout = c(1,3), type = c("l", "p"), ylab = "Y Label", xlab = "X Label", main = "Title of the Plot") dev.off() It creates a png file in the specified directory if directly run from R. But using C++ calls from RInside, I was not able to reproduce the same result. ( I could reproduce all base plots using C++ calls. Problem with only Lattice and ggplots ) I used