user2418838
user2418838

Reputation: 381

R histogram-reducing y range

I'm trying to draw a graph looks like below using r, and was wondering if there is a way to

1) omit the lower range of y values, but still start from 0.

2) Also, instead of numerical values, how do I label each bar in the histogram with texts?

I would appreciate any help. Thanks!

enter image description here

Upvotes: 2

Views: 486

Answers (1)

IRTFM
IRTFM

Reputation: 263362

The worth-a-read answer in the comments was using the same example of plotrix::gap.barplot that I picked but I've been working on those "squiggly lines":

require(plotrix)
twogrp<-c(rnorm(10)+4,rnorm(10)+20)
gap.barplot(twogrp, gap=c(8,16), xlab="Index", ytics=c(3,6,17,20),
                   ylab="Group values", main="Barplot with gap")
polygon(y=c( 7.5+c(-1,1)*.2*rep(1,length(twogrp)+2),  
             8.5+ c(-1,1)*.2*rep(1,length(twogrp)+2) ) ,
        x=c(0,seq_along(twogrp), rep(length(twogrp)+1, 2), # going to the right...
              rev(seq_along(twogrp)) ,0) ,                # and coming back to the left
        col="white", border="white")  # could also try border="lightblue"

enter image description here

There is also an axis.break function in plotrix that will give you the annotation on the axis. You would use the text function for labels inside the plot area.

Upvotes: 4

Related Questions