2

i am writing up a function to generate a stratified histogram. Here is my code. i would like to remove the inside border (so those stack counts are separated by colour only, not colour and border). any ideas?

data("iris")

strathist = function(x, y, ylab = "Frequency", xlab = "", main = ""){

  cols = hcl(h=seq(0, 300, by = 50), fixup = FALSE)

  h = hist(x, breaks = 20, plot = F)

  tb = table(y, cut(x, h$breaks))

  par(mar = rep(4, 4))

  plot.new()

  barplot(tb, space = 0, ylim = c(-0.4, 2 + max(h$count)), col = cols,
          ylab = ylab, xlab = xlab, main = main, axisnames = F) 

  axis(1, 0:(length(h$breaks)-1), h$breaks)

  box()

  legend("topright", c(rownames(tb)), cex = 0.8, fill = cols)
}

with(iris, strathist(Sepal.Length, Species, xlab = "Sepal.Length", main = "Stratified Histogram of Iris Species"))
user20650
  • 24,654
  • 5
  • 56
  • 91
ZWL
  • 319
  • 2
  • 4

0 Answers0