Hi, I'm trying to create a histogram with R. The problem is that the frequency is high for a couple of x-axis categories (e.g. 1500) and low for most of the x-axis categories (e.g. 50) r.789695.n4.nabble.com/file/n2237476/LK3_hist.jpg . When I create the histogram, it is not very informative, because only the high frequencies can be seen clearly. Is there any way I could cut the y-axis from the middle so that the y-axis values ranged for example from 0 to 300, and then again from 900 to 1500? -- View this message in context: r.789695.n4.nabble.com/Y-axis-range-in-histograms-tp2237476p2237476.html Sent from the R help mailing list archive at Nabble.com.
On 31/05/2010 10:49 AM, Aarne Hovi wrote:> Hi, > > I'm trying to create a histogram with R. The problem is that the frequency > is high for a couple of x-axis categories (e.g. 1500) and low for most of > the x-axis categories (e.g. 50) > r.789695.n4.nabble.com/file/n2237476/LK3_hist.jpg . When I create the > histogram, it is not very informative, because only the high frequencies can > be seen clearly. Is there any way I could cut the y-axis from the middle so > that the y-axis values ranged for example from 0 to 300, and then again from > 900 to 1500?Using a bar chart like that takes away most of the value of using a bar chart: you lose both area and length as visual clues to the value. Why not do something different? For example, x <- runif(1700) + rep(1:5, c(1500,50,55,45,50)) hist(x, breaks=5) # The one you don't like h <- hist(x, breaks=5, plot=FALSE) # Get the data plot(h$mids, h$counts, log="y") # Plot on a log scale abline(v=h$breaks,col="lightgray") # Indicate the bins Duncan Murdoch
A few ideas: Make a log-scale y-axis like: hist(my.data,...,log="y") argument yaxp can help make the ticks look pretty...see ?par. Or use various functions from the package `plotirx': axis.break and gap.barplot might be helpful. For those functions, you'll probably need to get your frequencies from the histogram, something like: my.freq <- hist(my.data,...,plot=FALSE)$counts you may also need to play with the x-axis tick labels to actually denote the correct bin for your frequencies. Good luck, hope that helps-- Andy On Mon, May 31, 2010 at 10:49 AM, Aarne Hovi <aarne.hovi@helsinki.fi> wrote:> > Hi, > > I'm trying to create a histogram with R. The problem is that the frequency > is high for a couple of x-axis categories (e.g. 1500) and low for most of > the x-axis categories (e.g. 50) > r.789695.n4.nabble.com/file/n2237476/LK3_hist.jpg . When I create > the > histogram, it is not very informative, because only the high frequencies > can > be seen clearly. Is there any way I could cut the y-axis from the middle so > that the y-axis values ranged for example from 0 to 300, and then again > from > 900 to 1500? > > -- > View this message in context: > r.789695.n4.nabble.com/Y-axis-range-in-histograms-tp2237476p2237476.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@r-project.org mailing list > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
On 31-May-10 14:49:43, Aarne Hovi wrote:> Hi, > > I'm trying to create a histogram with R. The problem is that the > frequency is high for a couple of x-axis categories (e.g. 1500) > and low for most of the x-axis categories (e.g. 50) > r.789695.n4.nabble.com/file/n2237476/LK3_hist.jpg . > When I create the histogram, it is not very informative, because > only the high frequencies can be seen clearly. Is there any way I > could cut the y-axis from the middle so that the y-axis values > ranged for example from 0 to 300, and then again from 900 to 1500?There may be specific rpovision for this in one of the extra graphics packages, but using plain hist() the only approach I can think of is on the folllowing lines. First create the histogram and name it: H <- hist(whatever) Then fake the high counts: ix <- H$counts > 400 ## which counts exceed 400 (say) H$counts[ix] <- H$counts[ix] - 500 ## counts > 900 -> 400+ Now plot the histogram without y-axis annotations, and with ylim=c(0,1100); then add annotations (0,100,200,300,900,1000,1100,...). Finally (perhaps) plot filled white boxes over the histogram bars with height range 330-370 (say) so that the break is obvious. Just first thoughts! Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 31-May-10 Time: 16:40:29 ------------------------------ XFMail ------------------------------
library(plotrix) break.axis() No clue how good this works with histograms though..... HTH Jannis Aarne Hovi schrieb:> Hi, > > I'm trying to create a histogram with R. The problem is that the frequency > is high for a couple of x-axis categories (e.g. 1500) and low for most of > the x-axis categories (e.g. 50) > r.789695.n4.nabble.com/file/n2237476/LK3_hist.jpg . When I create the > histogram, it is not very informative, because only the high frequencies can > be seen clearly. Is there any way I could cut the y-axis from the middle so > that the y-axis values ranged for example from 0 to 300, and then again from > 900 to 1500? >