issue with plot (type="h")

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

issue with plot (type="h")

Gasper Cankar
Hello everyone.

For reasons too long to explain I wanted to do plots similar to histograms with plot(type="h").
I ran into a problem - if I set line width too high, histogram isn't accurate anymore.

For example:

par(lend=2)
plot(c(2,4,3,2),ylim=c(0,5), type="h")
abline(h=3)

Column 3 appears just as high as it should. But if I do

par(lend=2)
plot(c(2,4,3,2),ylim=c(0,5), type="h",lwd=100)
abline(h=3)

then columns become too high. Can I correct the problem or is there another way to display my data correctly?

Thanks for help,



Gašper Cankar
National Examinations Centre,
Slovenia

______________________________________________
[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
Reply | Threaded
Open this post in threaded view
|

Re: issue with plot (type="h")

Sundar Dorai-Raj


Gasper Cankar wrote:

> Hello everyone.
>
> For reasons too long to explain I wanted to do plots similar to histograms with plot(type="h").
> I ran into a problem - if I set line width too high, histogram isn't accurate anymore.
>
> For example:
>
> par(lend=2)
> plot(c(2,4,3,2),ylim=c(0,5), type="h")
> abline(h=3)
>
> Column 3 appears just as high as it should. But if I do
>
> par(lend=2)
> plot(c(2,4,3,2),ylim=c(0,5), type="h",lwd=100)
> abline(h=3)
>
> then columns become too high. Can I correct the problem or is there another way to display my data correctly?
>

Try ?barplot instead:

bp <- barplot(c(2, 4, 3, 2), ylim = c(0, 5))
axis(side = 1, at = bp, labels = 1:4)
abline(h = 3)
box()

--sundar

______________________________________________
[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
Reply | Threaded
Open this post in threaded view
|

Re: issue with plot (type="h")

Peter Dalgaard
In reply to this post by Gasper Cankar
"Gasper Cankar" <[hidden email]> writes:

> Hello everyone.
>
> For reasons too long to explain I wanted to do plots similar to histograms with plot(type="h").
> I ran into a problem - if I set line width too high, histogram isn't accurate anymore.
>
> For example:
>
> par(lend=2)
> plot(c(2,4,3,2),ylim=c(0,5), type="h")
> abline(h=3)
>
> Column 3 appears just as high as it should. But if I do
>
> par(lend=2)
> plot(c(2,4,3,2),ylim=c(0,5), type="h",lwd=100)
> abline(h=3)
>
> then columns become too high. Can I correct the problem or is there another way to display my data correctly?
>
> Thanks for help,

lend=1 seems to cure it.

--
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - ([hidden email])                  FAX: (+45) 35327907

______________________________________________
[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
Reply | Threaded
Open this post in threaded view
|

Re: issue with plot (type="h")

Ben Bolker-2
In reply to this post by Gasper Cankar
Gasper Cankar <gasper.cankar <at> ric.si> writes:

>
> Hello everyone.
>
> For reasons too long to explain I wanted to do plots similar to histograms
with plot(type="h").
> I ran into a problem - if I set line width too high, histogram isn't accurate
anymore.

 try par(lend=1) instead.  Far from obvious, but see
Paul Murrell's article in R News #2 of 2004

  cheers
     Ben

______________________________________________
[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
Reply | Threaded
Open this post in threaded view
|

Re: issue with plot (type="h")

Manuel Morales
In reply to this post by Gasper Cankar
Hi Gašper

On Wed, 2006-02-22 at 14:12 +0100, Gasper Cankar wrote:

> Hello everyone.
>
> For reasons too long to explain I wanted to do plots similar to histograms with plot(type="h").
> I ran into a problem - if I set line width too high, histogram isn't accurate anymore.
>
> For example:
>
> par(lend=2)
> plot(c(2,4,3,2),ylim=c(0,5), type="h")
> abline(h=3)
>
> Column 3 appears just as high as it should. But if I do
>
> par(lend=2)
> plot(c(2,4,3,2),ylim=c(0,5), type="h",lwd=100)
> abline(h=3)
>
> then columns become too high. Can I correct the problem or is there another way to display my data correctly?

You need to use lend=1 or lend="butt" in your par() statement.

In my view, it would be nice to change the default to use lend=1 for
plot type = h, or at least to include a warning when square is used,
since the effect of increasing the lwd may not always be obvious.

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