lattice

R levelplot adjust axes

梦想与她 提交于 2019-12-22 12:21:11
问题 I want to plot the probability distribution function (PDF) as a heatmap in R using the levelplot function of the "lattice" package. I implemented PDF as a function and then generated the matrix for the levelplot using two vectors for the value ranges and the outer function. I want the axes to display the My issue is that am not able to add properly spaced tickmarks on the two axes displaying the two actual value ranges instead of the number of columns or rows, respectively. # PDF to plot

Add Different Labels to Secondary X-Axis of Levelplot in Lattice in R

淺唱寂寞╮ 提交于 2019-12-22 09:47:41
问题 I've managed to label the secondary X-axis in a levelplot using scale=list((alternating=3)) as solved by @KoenV here: How to Add Labels to Top X-Axis of Levelplot in Lattice Package Now this duplicates the primary X-axis labels onto the secondary X-axis as can be seen by running the code below. However, I need to add different labels to the secondary X-axis. Does anyone know how to do this? In the example below I would like to have 'hor' as the primary X-axis labels and 'hor2' as the

controlling the inner figure margin within grid.layout

。_饼干妹妹 提交于 2019-12-22 08:29:50
问题 I'm trying to plot multiple lattice plots in a grid. To do so I'm using the following code: plot <- xyplot(1:10~1:10) page.layout <- grid.layout(nrow = 2, ncol = 1, widths = unit(c(1), "null"), heights = unit(c(1), "null"), default.units = "null", respect = FALSE, just = "centre") pushViewport(viewport(layout = page.layout)) pushViewport(viewport(layout.pos.row = 1)) par(mar = c(5, 4, 4, 2)) print(plot, newpage = FALSE) popViewport() pushViewport(viewport(layout.pos.row = 2)) par(mar = c(5, 4

R: specifying color for different facets / panels in lattice

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-22 06:56:21
问题 My data is as follows: grp = rep(1:2, each = 100) chr = c(rep(1:10, each = 10), rep(1:10, each = 10)) var = paste (grp, "chr", chr, sep = "") pos = (rep(1:10, 20)) yvar = rnorm(200) mydf = data.frame (var, pos, yvar) require( lattice) xyplot(yvar ~ pos| factor(var), data = mydf, layout = c(1,10), type = c("g", "h"), col = "darkolivegreen", lwd = 4) (1) I want to put different colors to alternate graph / panel - for example - 2chr1 is darkolive green but chr10 is say purple. then again dark

Controlling placement of empty lattice panels

不打扰是莪最后的温柔 提交于 2019-12-22 05:23:43
问题 When plotting fewer panels than the full grid you get a gap without a panel. Most lattice functions puts the gap in the top right, but I would like to have it in the lower right, as marginal.plot does (see the picture). Is there a way to make other lattice functions do the same? I know the panel order is decided by the order of the factor levels of the conditioning variable, or by using the index.cond argument, but that does not help me here. I have tried to decipher the code of marginal.plot

Symmetrical, violin plot-like histogram?

邮差的信 提交于 2019-12-22 05:23:33
问题 How can I make a histogram in which the center of each bar lies along a common axis? This would look like a violin plot with step-shaped edges. I'd like to do this in Lattice, and don't mind customizing panel functions, etc., but would be happy to use base R graphics or even ggplot2. (I haven't yet thrown myself into ggplot2, but will take the plunge at some point.) (Why do I want to do this? I think it might be a useful replacement for a violin plot when data is discrete and occurs at a few

Using grconvertX/grconvertY in ggplot2

北城余情 提交于 2019-12-22 04:42:44
问题 I am trying to figure out how to use grconvertX/grconvertX in ggplot. My ultimate goal is to to add annotation to a ggplot2 figure (and possibly lattice ) with grid.text and grid.lines by going from user coordinates to device coordinates. I know it can be done with grobs but I am wondering if there is an easier way. The following code allows me to pass values from user coordinates to ndc coordinates and use those values to annotate the plot with grid.text . graphics.off() # close graphics

Change x-axis limits on stratigraphic plots (ie. multi-panel plots)

两盒软妹~` 提交于 2019-12-22 04:33:19
问题 How can I manually adjust the x axis limits for each panel in a stratigraphic plot? For example, here's Stratiplot from analogue : library(analogue) data(V12.122) Depths <- as.numeric(rownames(V12.122)) (plt <- Stratiplot(Depths ~ O.univ + G.ruber + G.tenel + G.pacR, data = V12.122, type = c("h","l","g","smooth"))) How could I, for example, change the xlim of G.ruber to c(0.3, 0.9) and G.pacR to c(0, 0.75)? Or, another possibility, here is strat.plot from rioja : library(rioja) library(vegan)

Passing conditioning variables to xyplot in a function in lattice

╄→尐↘猪︶ㄣ 提交于 2019-12-21 22:07:44
问题 My dataframe has many columns. I wish to perform separate but similar xyplot() calls on many of these columns without endlessly copying the lengthy xyplot() call. I've tried writing a function to do this, but lattice does not seem to accept text arguments as conditioning variables. Duplicating xyplot calls are making my code unwieldy. Any ideas? df=data.frame(ts=c(1:100),x=runif(100),y=3,z=rnorm(100)) # This is the clunky approach I want to avoid tp <- xyplot(x~ts, df) # imagine ~10 lines of

barchart in R using lattice

老子叫甜甜 提交于 2019-12-21 20:45:40
问题 This is my code: d<-data.frame(column1=rep(Names, each=1),column2=rep(c("one"),1),column3=values) barchart(column3 ~ column1, groups=column2, d, auto.key = list(columns = 1)) One of my values is negative. On my picture I see all the bars starting from negative values and growing up to their values, but I want to see all the bars starting at 0 (one bar has revers direction). How can I do this? I'm not sure about lattice, any other way is ok. I tried barplot, it plots in the right way, but my