Reputation: 381
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!
Upvotes: 2
Views: 486
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"
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