Quantcast

barplot problem

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

barplot problem

jhmicro
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.

Take care,

-jh

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: barplot problem

Michael Weylandt
It sounds like you want something of the form

plot(distance, data, type = "h")

But the lines might be too thin: try adding lwd = NUM to increase the
thickness.

Hope this helps,
Michael

On Sat, May 26, 2012 at 11:26 PM, jack hietpas <[hidden email]> 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.
>
> Take care,
>
> -jh
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: barplot problem

Jim Lemon
In reply to this post by jhmicro
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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: barplot problem

jhmicro
Hi Jim- Thanks for your help.  I am not sure how to execute your
instructions... I used the space argument to to equally space the bars
(barplot(data, space=c(1,1,1,1,1,1)).

How do I get the "x positions in the return values".  Take care,

-jh



On Sun, May 27, 2012 at 3:42 AM, Jim Lemon <[hidden email]> wrote:

> 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
>
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: barplot problem

Uwe Ligges-3


On 27.05.2012 17:46, jack hietpas wrote:
> Hi Jim- Thanks for your help.  I am not sure how to execute your
> instructions... I used the space argument to to equally space the bars
> (barplot(data, space=c(1,1,1,1,1,1)).
>
> How do I get the "x positions in the return values".  Take care,


xp <- barplot(.....)

Then take a look into xp.

See also ?barplot!

Uwe Ligges


> -jh
>
>
>
> On Sun, May 27, 2012 at 3:42 AM, Jim Lemon<[hidden email]>  wrote:
>
>> 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
>>
>>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: barplot problem

Richard M. Heiberger
In reply to this post by jhmicro
I would use barchart in lattice.  To get control of spacing you need to use
the panel.barchart with
the xyplot function.  I show two options below.  The first labels the
distance scale with the default
values seq(0,300,50),  The second labels the bars with their distance value.

tmp <-
data.frame(y=c(-0.0002129061,0.0000000000,-0.0002699561,0.0163883061,0.0400000000),
                  distance=c(0, 71, 172, 206, 292))
xyplot(y ~ distance, data=tmp, horizontal=FALSE, origin=0,
       panel=panel.barchart, box.width=20)
xyplot(y ~ distance, data=tmp, horizontal=FALSE, origin=0,
       panel=panel.barchart, box.width=20,
       scales=list(x=list(at=tmp$distance)))



On Sat, May 26, 2012 at 11:26 PM, jack hietpas <[hidden email]> 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.
>
> Take care,
>
> -jh
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: barplot problem

jhmicro
Richard- thank you very very much, this is exactly what I needed.  I have
not previously used lattice graphics, I will have to experiment more with
this package.

Also thanks to everyone for your input.

-jh

On Sun, May 27, 2012 at 1:04 PM, Richard M. Heiberger <[hidden email]>wrote:

> I would use barchart in lattice.  To get control of spacing you need to
> use the panel.barchart with
> the xyplot function.  I show two options below.  The first labels the
> distance scale with the default
> values seq(0,300,50),  The second labels the bars with their distance
> value.
>
> tmp <-
> data.frame(y=c(-0.0002129061,0.0000000000,-0.0002699561,0.0163883061,0.0400000000),
>                   distance=c(0, 71, 172, 206, 292))
> xyplot(y ~ distance, data=tmp, horizontal=FALSE, origin=0,
>        panel=panel.barchart, box.width=20)
> xyplot(y ~ distance, data=tmp, horizontal=FALSE, origin=0,
>        panel=panel.barchart, box.width=20,
>        scales=list(x=list(at=tmp$distance)))
>
>
>
> On Sat, May 26, 2012 at 11:26 PM, jack hietpas <[hidden email]>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.
>>
>> Take care,
>>
>> -jh
>>
>>        [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html>
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Loading...