R: How to change the text of stripes in the xyplot R-grid

I am trying to use a histogram function to plot the density of some data. A sample data format is as follows:

   library(lattice)
   index<-c(1,1,1,2,2,2,2)
   freq<-c(3,4,6,3,6,2,2)
   D<-data.frame(index,freq)
   histogram(~D$freq|D$index)

I want the index number to be printed as strip text for each histogram (i.e., in this example, 1 and 2 on top of the histograms respectively instead of the ones currently printed D$index), but I don't know how easy the way to do this is (I know what I need to use is strip.custom()possible and change var.namecorrectly, but I do not know how to iterate over it in my index)

+3
source share
2 answers

If you change the index variable by a coefficient, you get what should be the default, i.e. prints pebble levels in a strip:

library(lattice)
    index<-factor(c(1,1,1,2,2,2,2))
    freq<-c(3,4,6,3,6,2,2)
    D<-data.frame(index,freq)
    histogram(~D$freq|D$index)

strip.default:

histogram(~freq|index, data=D, strip = 
      function(..., style){ strip.default(..., style = 4)}  )
+4

index a factor

index <- c(1,1,1,2,2,2,2)
freq <- c(3,4,6,3,6,2,2)
D <- data.frame(index=factor(index), freq)
histogram(~D$freq|D$index)

Histogram with index

histogram(~freq|index, D) .

+2

All Articles