Building multiple histograms on one panel

I am trying to plot several histograms of some variables in a data frame in the same panel. Below is the following code:

library(lattice) dd <- data.frame(gp = factor(rep(paste('Group', 1:6, sep = ''), each = 100)), x = rnorm(600)) histogram( ~ x | gp, data = dd) histogram( ~ x | gp, data = dd, as.table = TRUE) 

This puts the x data in groups 1 through 6. In this framework, we already have numbers in certain categories. For example, suppose I want to plot a bar graph of height, weight, and average blood pressure (variables in a date frame) in the same panel. How can I do this without having to create a new dataset and groups from 1 to 3?

+4
source share
1 answer

No need to redo the data here.

  histogram( ~ height +age +weight ,data = dd) 

Then you can use layout to change the display order of the panels. For instance:

  histogram( ~ height +age +weight ,layout=c(1,3),data = dd) 

This will result in 3 histograms in 3 panels.

EDIT

to add a title you can use main

 histogram( ~ height +age +weight ,layout=c(1,3),data = dd, main='PLEASE READ LATTICE HELP') 

Note: Parameter parameters are shared between different lattice functions. For example, the entry xlab: See xyplot . when you go to xyplot help you can read:

 main: Typically a character string or expression describing the main title to be placed on top of each page. Defaults to NULL 
+8
source

All Articles