lattice

How to have two different size legends in one ggplot?

纵饮孤独 提交于 2019-12-10 17:16:17
问题 Imagine I plot this toy data: lev <- c("A", "B", "C", "D") nodes <- data.frame(ord=c(1,1,1,2,2,3,3,4), brand= factor(c("A", "B", "C","B", "C","D", "B","D"), levels=lev), thick=c(16,9,9,16,4,1,4,1)) edge <- data.frame(ord1=c(1,1,2,3), brand1=factor(c("C","A","B","B"), levels=lev),ord2=c(2,2,3,4), brand2=c("C","B","B","D"), N1=c(2,1,2,1), N2=c(5,5,2,1)) ggplot() + geom_point(data = nodes, aes(x = ord, y = brand, size = sqrt(thick)), color = "black", shape = 16, show.legend = T) + scale_x

How to get shaded background in xyplot in R?

守給你的承諾、 提交于 2019-12-10 15:11:49
问题 using xyplot from the lattice package, I plot a time series over a number of years. I would to add a shaded area for some of these years to indicate that this time period was "special" (e.g. war). Please apologize if this is trivial, but I could not figure out how to do that, so I would be happy if someone could help me out, or at least point me in the right direction. I think my main problem is that I don't really know how to approach this problem. I am still relatively new to R, and to

Combine a ggplot2 object with a lattice object in one plot

只愿长相守 提交于 2019-12-10 11:16:24
问题 I would like to combine a ggplot2 with a lattice plot object. Since both packages are based on grid I was wondering whether this is possible? Ideally, I would do everything in ggplot2 but I cannot plot a 3d scatter. So assume I have the following data: set.seed(1) mdat <- data.frame(x = rnorm(100), y = rnorm(100), z = rnorm(100), cluster = factor(sample(5, 100, TRUE))) First, I want to create a scatterplot matrix in ggplot2 : library(ggplot2) library(gtools) library(plyr) cols <- c("x", "y",

How are trellis axis limits calculated?

非 Y 不嫁゛ 提交于 2019-12-10 10:01:25
问题 Say I want to create an ordinary xyplot without explicitly specifying axis limits, then how are axis limits calculated? The following line of code produces a simple scatter plot. However, axis limits do not exactly range from 1 to 10, but are slightly expanded to the left and right and top and bottom sides (roughly by 0.5). library(lattice) xyplot(1:10 ~ 1:10, cex = 1.5, pch = 20, col = "black", xlab = "x", ylab = "y") Is there any way to determine the factor by which the axes were expanded

Combining plots created by R base, lattice, and ggplot2

旧巷老猫 提交于 2019-12-10 03:52:18
问题 I know how to combine plots created by R graphics. Just do something like attach(mtcars) par(mfrow = c(3,1)) hist(wt) hist(mpg) hist(disp) However, now I have plots by three different graphic systems # 1 attach(mtcars) boxplot(mpg~cyl, xlab = "Number of Cylinders", ylab = "Miles per Gallon") detach(mtcars) # 2 library(lattice) attach(mtcars) bwplot(~mpg | cyl, xlab = "Number of Cylinders", ylab = "Miles per Gallon") detach(mtcars) # 3 library(ggplot2) mtcars$cyl <- as.factor(mtcars$cyl) qplot

How to get spplot (lattice) to not draw borders around polygons

假如想象 提交于 2019-12-10 03:21:12
问题 I have a tally by zip code which is a lot of polygons to plot (30,357 to be precise). Consequently when I pdf the spplot all I see are the borders not the choropleth interiors. Therefore, I'd like to turn off plotting the borders, or at least be able to make them much, much thinner. However, digging around in ?spplot and its various offshoots (the panel function, levelplot, etc.) have come up empty. Here's an example to work with (the borders aren't that prominent here but they would be given

Custom placement of spplot legend in the map

孤街浪徒 提交于 2019-12-10 03:11:12
问题 Is it possible to place the spplot (spplot polygons) legend within the map, in lower left corner, like this? The closest I've been able to get is this (I am not posting my data, I just use the example data instead, so in this case, try to place the legend in top left part of the map): data(meuse.grid) gridded(meuse.grid)=~x+y spplot(meuse.grid[,'dist'], colorkey = list(space = "left", height = 0.5) ) But the legend is in the middle of the page and is outside of the map. Unfortunatelly,

Change text on strips in lattice plots

一世执手 提交于 2019-12-10 01:06:43
问题 how do I change the text displayed in the strips of lattice plots? example: suppose I have a data frame test consisting of 3 columns x [1] 1 2 3 4 5 6 7 8 9 10 y [1] "A" "A" "A" "A" "A" "B" "B" "B" "B" "B" a [1] -1.9952066 -1.7292978 -0.8789127 -0.1322849 -0.1046782 0.4872866 [7] 0.5199228 0.5626998 0.6392686 1.6604549 a normal call to a lattice plot xyplot(a~x | y,data=test) will give the plot with the Text 'A' and 'B' on the strips How can I get different texts written on the strips? An

Plotting a rather complex chart using R and axis break()

我怕爱的太早我们不能终老 提交于 2019-12-08 22:02:29
Hi R users and programmers, I have a data set consisting of 4563 amino acids of a protein. Using three different treatments and two different oxidants, amino acids in this protein were oxidized. I would like to plot the position of those oxidations in a chart based on the treatment. Different line size will represent varying oxidant concentration and line type (dashed and solid) will represent different types of oxidant. I would like to break the axis at each 1000 amino acid. I have created a similar template with excel and gimp (which is rather time consuming and possibly inappropriate!). 0

Plotting straight surface with lattice::wireframe()

限于喜欢 提交于 2019-12-08 12:15:54
问题 Assume I want to plot the following dataframe: df <- data.frame(expand.grid(1:10,1:10),rep(10,100)) colnames(df) <- c("x","y","z") with the lattice wireframe() function: wireframe(z~x*y,df,colorkey=TRUE,drape=TRUE) How do I get it to plot the given coordinates? I would assume it has something to do with having to scale/adjust the z-axis as the automatic scaling within wireframe is probably confused by all z-coordinates being equal. 回答1: Just add a zlim argument. wireframe(z~x*y,df,colorkey