5

I have two histograms in one window (using facet) and I would like control over the color of the outline and the fill. I've tried looking up color scales, aes(), + color, + fill, including color and fill in qplot, all resulting in expected plots!

My code can be found below. (Note: mussel2 has two columns concentration (a list of numbers) and waterbody (listed or reference). I can provide the data if necessary.

I understand this is an elementary question, so I do appreciate your time.

qplot(data=mussel2,
    x = Concentration,
    xlim = x_lim, 
    ylim = y_lim, 
    xlab = expression(paste("Concentrations of DDE (", mu, "g/g)")), 
    ylab = "Frequency",
    binwidth = 1.5)+ 
    theme(legend.position="none")+
    facet_grid(Waterbody~.)
Andre Silva
  • 4,782
  • 9
  • 52
  • 65
user2793148
  • 51
  • 1
  • 1
  • 2
  • 1
    Welcome to SO! It is great that you offer us to provide data. However, it is much better if you provide a [minimal, reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610) right away. This time you received two very rapid answers, but in general you are much more likely to receive help if you provide a simple dummy data set. Thanks and good luck with your plots! – Henrik Sep 18 '13 at 21:32

2 Answers2

9

If you want to keep the qplot format, try the following:

library(ggplot2)

qplot(diamonds$carat, 
      xlab="Carat", 
      geom="histogram", 
      ylab="Count", 
      binwidth=0.25, 
      fill=I("grey"), 
      col=I("black"))

enter image description here

Andre Silva
  • 4,782
  • 9
  • 52
  • 65
4

Use ggplot if you want to tweak things. I left out some of your options, but you can probably work out how to put them in.

ggplot(data = mussel2, aes(x = Concentration)) +
    geom_bar(binwidth = 1.5, fill = "firebrick4", color = "dodgerblue2") +
    scale_x_continuous(limits = x_lim) + 
    labs(y = "Frequency") +
    facet_wrap(~ Waterbody)
Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294