Questions tagged [lattice]

lattice is a package that forms part of base R and allows the creation of trellis-type graphics.

R's lattice package, developed by Deepayan Sarkar, is a port of Bell Laboratories' Trellis Graphics to R. It is one of the three main graphics options in R, the other two being R's base graphics capabilities and .

Repositories

Vignettes

Books

Other resources

R packages extending lattice

  • latticeDensity: Density estimation and nonparametric regression on irregular regions.
  • latticeExtra: Extra Graphical Utilities Based on Lattice.
  • latticist: A graphical user interface for exploratory visualisation.
  • latticedl: Lattice direct labels, for automatically labeling points.

Related tags

1185 questions
319
votes
11 answers

How to save a plot as image on the disk?

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…
blakc05
  • 3,349
  • 4
  • 13
  • 6
74
votes
6 answers

How to plot a function curve in R

What are the alternatives for drawing a simple curve for a function like eq = function(x){x*x} in R? It sounds such an obvious question, but I could only find these related questions on stackoverflow, but they are all more specific Plot line…
sjdh
  • 3,077
  • 5
  • 20
  • 27
70
votes
3 answers

Lattice: multiple plots in one window?

I'm trying to put multiple lattice plots in one window using levelplot by setting par(mfrow=c(2,1)) but it seems to be ignoring this. Is there a particular function for setting multiple plots in lattice?
Chris
  • 701
  • 1
  • 6
  • 3
36
votes
4 answers

Reproducing lattice dendrogram graph with ggplot2

Is this possible to reproduce this lattice plot with ggplot2? library(latticeExtra) data(mtcars) x <- t(as.matrix(scale(mtcars))) dd.row <- as.dendrogram(hclust(dist(x))) row.ord <- order.dendrogram(dd.row) dd.col <-…
MYaseen208
  • 19,213
  • 32
  • 133
  • 260
27
votes
4 answers

How to add boxplots to scatterplot with jitter

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…
rnso
  • 20,794
  • 19
  • 81
  • 167
27
votes
6 answers

Diagonal labels orientation on x-axis in heatmap(s)

Creating heatmaps in R has been a topic of many posts, discussions and iterations. My main problem is that it's tricky to combine visual flexibility of solutions available in lattice levelplot() or basic graphics image(), with effortless clustering…
Geek On Acid
  • 6,022
  • 3
  • 40
  • 60
22
votes
3 answers

R: What are the pros and cons of using Lattice versus ggplot2?

R: What are the pros and cons of using Lattice versus ggplot2?
Thomas Bratt
  • 40,822
  • 34
  • 113
  • 133
21
votes
3 answers

Embedding a miniature plot within a plot

Does anybody know of a general way to embed plots into other plots to produce something like the mockup below? I know that in lattice you can do it with print(..., more=TRUE, positions=...) as explained in this question, and I guess ggplot has a…
Backlin
  • 13,682
  • 1
  • 43
  • 76
18
votes
4 answers

plotting two vectors of data on a GGPLOT2 scatter plot using R

I've been experimenting with both ggplot2 and lattice to graph panels of data. I'm having a little trouble wrapping my mind around the ggplot2 model. In particular, how do I plot a scatter plot with two sets of data on each panel: in lattice I could…
JD Long
  • 55,115
  • 51
  • 188
  • 278
17
votes
1 answer

How to set strip label font size in lattice graphics in R

I've created a lattice plot with three panels. I can control the font size for the axis and tick labels, but I haven't been able to figure out how to increase the font size of the strip labels. Here's a concrete example: # See below for the fake…
eipi10
  • 81,881
  • 20
  • 176
  • 248
16
votes
5 answers

R: how to change lattice (levelplot) color theme?

The default theme on my installation is something which maps the values to pink and cyan. How to change it for example to a gray scale theme?
user442446
  • 989
  • 3
  • 10
  • 13
15
votes
2 answers

Relationship between plotting packages in R

I am just starting out with R, and beginning to start producing charts. I am aware that there are at least three different plotting packages, the standard one, ggplot2 and lattice. Are these packages complementary, or do they cover much the same…
fmark
  • 50,804
  • 25
  • 88
  • 106
15
votes
4 answers

beautiful Pie Charts with R

Let's say I have this simple data: mydata <- data.frame(group=c("A", "B", "0", "AB"), FR=c(20, 32, 32, 16)) If I want to create a pie chart from this dataframe I can do: with(mydata,pie(FR, labels=paste0(as.character(group), " ", FR, "%"),…
skan
  • 6,456
  • 11
  • 47
  • 83
14
votes
2 answers

How to change points and add a regression to a cloudplot (using R)?

To make clear what I'm asking I've created an easy example. Step one is to create some data: gender <- factor(rep(c(1, 2), c(43, 41)), levels = c(1, 2),labels = c("male", "female")) numberofdrugs <- rpois(84, 50) + 1 geneticvalue <-…
MarkDollar
  • 143
  • 1
  • 6
14
votes
1 answer

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

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…
BDM
  • 464
  • 2
  • 7
  • 15
1
2 3
78 79