[R] barplot problem

Jim Lemon jim at bitwrit.com.au
Sun May 27 09:42:23 CEST 2012


On 05/27/2012 01:26 PM, jack hietpas wrote:
> Hello- I am having trouble making a barplot...
>
> The y-values are:
> data=c(-0.0002129061,0.0000000000,-0.0002699561,0.0163883061,0.0400000000).
>
> The x-values are distance=c(0, 71, 172, 206, 292).
> The desired x-range is 0 and ~300+ (kilometers), range=seq(0,300,1)
>
> I would like to make a bar plot with the bar locations along the x-axis
> spaced according to their distances.
>
> I have tried barplot(distance, data)... but this produces a very strange
> plot.
>
> plot(distance, data) is almost correct, except it is a scatter plot.
>
> Thanks for any help you can provide, I must be missing something very
> obvious.
>
Hi Jack,
You can use the space argument in barplot to do this by running barplot 
with equally spaced bars, and getting the x positions of the bars in the 
return values. Then just space the bars out as needed with a vector of 
"space" values. This should give you a reasonable looking x axis, but 
you might have to pass the cumulative sum of bar positions and spaces if 
you want each bar labelled.

Jim



More information about the R-help mailing list