2

I have been successful in making the Histogram for the variable wind speed for all years and months in my data set. But I want the the x-axis labeled at 1 mile/hr intervals.Each bin is also of 1 mile/hr interval. Currently by default the x axis is labeled at 20 miles/hour intervals.

Here is my R code.

histogram(~ as.numeric(spd) | factor(month) + factor(year), data = spd_sub, 
  xlab = "spd in miles/hour", 
  nint= max(as.numeric(spd))-min(as.numeric(spd)), layout = c(1, 1))

Any idea how to do this?

joran
  • 169,992
  • 32
  • 429
  • 468
Ridhima
  • 21
  • 1
  • 2
  • Your code is not reproducible. Please make a mock example (see here: http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – Roman Luštrik Sep 10 '11 at 17:15

1 Answers1

5

Maybe this could be little something to think about. Notice the use of scales.

library(lattice)
Depth <- equal.count(quakes$depth, number=8, overlap=.1)
xyplot(lat ~ long | Depth, data = quakes)

This gives you the following graph. enter image description here

And if you set the scales argument:

xyplot(lat ~ long | Depth, data = quakes,
        scales = list(y = list(at = seq(from = 0, to = -50, by = -10))))

enter image description here

One gratis with a histogram (changed the tick marks and rotated them):

histogram( ~ height | voice.part, data = singer,
    xlab = "Height (inches)", type = "density",
    panel = function(x, ...) {
        panel.histogram(x, ...)
        panel.mathdensity(dmath = dnorm, col = "black",
            args = list(mean=mean(x),sd=sd(x)))
    },
    scales = list(x = list(at = seq(60, 80, by = 2), rot = 45)))

enter image description here

Roman Luštrik
  • 69,533
  • 24
  • 154
  • 197
  • Let me be more specific. I have daily data on wind speed in miles per hour for 10 years and I wish to make a histogram of wind speed for each of the month for all years where the x axis is labelled at 1 mile per hour intervals. I cannot use the seq function because I don't know the number of bins in all of the histograms before hand. – Ridhima Sep 10 '11 at 17:54
  • 1
    I'm pretty sure you can have more than you need, so `seq(-1000,1000,by=1)` would only label those that fall on the plot. That is, find out the farthest you need to go on either side and use that for all plots. – Aaron left Stack Overflow Sep 10 '11 at 20:34
  • Thanks a lot. It indeed worked but my x axis scales seem a little out of place. I wanted to show my graph here that I have as a pdf or opened in Quartz but presently I don't know how to do that. Can anybody tell me how can I get my R graph here so my question is clear? – Ridhima Sep 11 '11 at 08:10
  • @Ridhima, see `?jpeg` or say `?png`. – Roman Luštrik Sep 11 '11 at 10:14