0

This is a followup to this, this, and this question.

Currently, I have a twelve-panel lattice in which the same dark histogram outline is superimposed on twelve different solid gray histograms:

Twelve panels with two histograms in each, one as an outline over the other

This makes it easy to compare the new data in each panel with the same set of other data. Leaving out some details that are irrelevant to this question, my code looks like this:

histogram(~ foo | bar,
          data=mydata[mydata$bar!="none",],  # get only the 12 categories
          col=mylightgray, border=mylightgray,
          panel=function(...){panel.histogram(...) # add histogram to ea. panel:
                              panel.histogram(x=mydata[mydata$bar=="none",]$foo,
                                  col="transparent", border="black")})

Now I want to reverse the colors, so to speak: I want to superimpose different outline histograms on the same solid gray histogram.

Here's the problem:

If I simply swap the colors, so that the main histogram has col="transparent" and border="black", while the panel function histogram uses mylightgray, the gray histograms will be on top, and will obscure parts of the outline histogram, which defeats the purpose of putting two histograms in one panel.

On the other hand, if I swap the data specification, so that the outer main histogram uses bar=="none" and the panel histogram uses bar!="none", I only get one panel.

The problem is that it's the main histogram call, not the extra panel function, that both writes first and also controls the number of panels. It appears to be impossible to create multiple panels in which the plot that's on the bottom is the same--unless I just create a dataframe with twelve duplicates of the same data. I wonder if there's a solution without producing special data.

Community
  • 1
  • 1
Mars
  • 8,689
  • 2
  • 42
  • 70
  • 2
    Please include a minimal [reproduicble example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) in the question itself. It made it harder to help you if we have to track down partial information in other questions. Also maybe include a picture/sketch so we know exactly what you want – MrFlick Aug 17 '16 at 20:05
  • You might find this post of interest: https://drsimonj.svbtle.com/plotting-background-data-for-groups-with-ggplot2 – Simon Jackson Aug 18 '16 at 02:11
  • @MrFlick, will do. I thought it might not be necessary in this case. – Mars Aug 18 '16 at 16:51
  • Thanks @SimonJackson. I've never used ggplot2 and am comfortable with Lattice, so I continue in the same pattern ... but maybe in this case it would be worth trying ggplot2. – Mars Aug 18 '16 at 20:24

1 Answers1

0

Swap the colors and the order of the panel.histograms calls. That is, plot the gray histogram first.

DaveTurek
  • 1,297
  • 7
  • 8