[R] adding additional information to histogram

Raphael Bauduin rblists at gmail.com
Thu Jan 26 17:12:50 CET 2012


Hi,

I am a beginner with R, and I think the answer to my question will
seem obvious, but after searching and trying without success I've
decided to post to the list.

I am working with data loaded from a csv filewith these fields:
  order_id, item_value
As an order can have multiple items, an order_id may be present
multiple times in the CSV.

I managed to compute the total value  and the number of items for each order:

  oli <- read.csv("/tmp/order_line_items_data.csv", header=TRUE)
  orders_values <- tapply(oli[[2]], oli[[1]], sum)
  items_per_order <- tapply(oli[[2]], oli[[1]], length)

I then can display the histogram of the order values:

  hist(orders_values, breaks=c(10*0:20,800), xlim=c(0,200), prob=TRUE)

Now on this histogram, I would like to display the average number of
items of the orders in each group (defined with the breaks).
So for the bar of orders with value 0 to 10, I'd like to display the
average number of items of these orders.

Thanks in advance

Raph



More information about the R-help mailing list