Re: [R] hist for two sets

From: Marc Schwartz <MSchwartz_at_mn.rr.com>
Date: Thu 14 Sep 2006 - 23:55:34 GMT

On Thu, 2006-09-14 at 19:37 -0400, Ethan Johnsons wrote:
> A quick question, please.
>
> x = c(0.0001, 0.0059, 0.0855, 0.9082)
> y = c(0.54, 0.813, 0.379, 0.35)
>
> where A = 1st set, B = 2nd set, C = 3rd set, D = 4th set respectivley.
>
> How do you make hist plot side by side for x & y?
>
> i.e. 0.0001 and then to the right 0.54, 0.0059 and then to the right 0.813,
> etc.
>
> thx much

You don't want a histogram, but a barplot:

 x <- c(0.0001, 0.0059, 0.0855, 0.9082)
 y <- c(0.54, 0.813, 0.379, 0.35)

 # create a two row matrix with x and y
 height <- rbind(x, y)

 # Use height and set 'beside = TRUE' to get pairs
 # save the bar midpoints in 'mp'
 # Set the bar pair labels to A:D
 mp <- barplot(height, beside = TRUE, ylim = c(0, 1), 
               names.arg = LETTERS[1:4])

 # Draw the bar values above the bars
 text(mp, height, labels = format(height, 4), pos = 3, cex = .75)

See ?barplot, ?text and ?format (or ?formatC or ?sprintf).

HTH, Marc Schwartz



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri Sep 15 09:58:09 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 15 Sep 2006 - 02:30:05 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.