开发者

R: How to change the text of strips in R's lattice xyplot

I am trying to use the function histogram to plot the density of some data. A sample format of data 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 to have the index number printed as the strip text for each histogram (i.e. in this example, 1 and 2 on top of histograms respectively instead of currently printed D$index), but I don't know of an easy way to do it (I know that I have to use 开发者_JAVA技巧strip.custom() possibly, and change var.name properly, but I don't know how to iterate over it according to my index)


If you change the index variable to a factor you get what is supposed to be the default behavior, i.e. printing the shingle levels in the 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)

Just for fun you can play with the style variable in strip.default:

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


Make 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)

R: How to change the text of strips in R's lattice xyplot

And it's nicer to look on histogram(~freq|index, D) way to call lattice functions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜