Ein eingebundener Text mit undefiniertem Zeichensatz wurde abgetrennt. Name: nicht verf?gbar URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20080929/e8ff7cb6/attachment.pl>
histogram-like plot with two variables
6 messages · Jörg Groß, jim holtman, Duncan Murdoch +3 more
Try: plot(x,y,type='s') lines(x,y, type='h')
On Sun, Sep 28, 2008 at 10:02 PM, J?rg Gro? <joerg at licht-malerei.de> wrote:
Hi,
I want to plot a binomial propability distribution.
I know how to generate the data;
x <- seq(from=0, to=14, by=1)
y <- dbinom(x, 14, 0.7, log = FALSE)
but what I don't know is how to plot this within a histogram like plot.
Because the histogram function only accepts one variable.
Is there a way to get the look of "hist()" with two variables?
I tried:
plot(x,y, type="h")
but the bars are very thin -is there a way to define the width?
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org 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.
Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
On 28/09/2008 10:02 PM, J?rg Gro? wrote:
Hi, I want to plot a binomial propability distribution. I know how to generate the data; x <- seq(from=0, to=14, by=1) y <- dbinom(x, 14, 0.7, log = FALSE) but what I don't know is how to plot this within a histogram like plot. Because the histogram function only accepts one variable. Is there a way to get the look of "hist()" with two variables? I tried: plot(x,y, type="h") but the bars are very thin -is there a way to define the width?
You could use barplot(): barplot(y,names=x) You could also do it with plot.histogram, but it's trickier, because it's designed for continuous data. For example, dat <- hist(x, plot=FALSE, breaks=c(-1,x)+0.5) dat$density <- y plot(dat, freq=FALSE) Duncan Murdoch
J?rg Gro? wrote:
Hi, I want to plot a binomial propability distribution. I know how to generate the data; x <- seq(from=0, to=14, by=1) y <- dbinom(x, 14, 0.7, log = FALSE) but what I don't know is how to plot this within a histogram like plot. Because the histogram function only accepts one variable. Is there a way to get the look of "hist()" with two variables? I tried: plot(x,y, type="h") but the bars are very thin -is there a way to define the width?
Hi Jorg, Does this do what you want? library(plotrix) barp(y,names.arg=0:14) Jim
On Mon, Sep 29, 2008 at 04:02:05AM +0200, J?rg Gro? wrote:
Hi, I want to plot a binomial propability distribution. I know how to generate the data; x <- seq(from=0, to=14, by=1) y <- dbinom(x, 14, 0.7, log = FALSE) I tried: plot(x,y, type="h") but the bars are very thin -is there a way to define the width?
yes - the lwd parameter controls line width. E.g.: plot(x,y, type='h', lwd=5) This is the way I usually plot count data - I prefer this over something that looks like a normal histogram, because it reminds me that I am looking at discrete values. cu Philipp
Dr. Philipp Pagel Lehrstuhl f?r Genomorientierte Bioinformatik Technische Universit?t M?nchen Wissenschaftszentrum Weihenstephan 85350 Freising, Germany http://mips.gsf.de/staff/pagel
An added note, if you use this approach, then you should probably set the lend parameter as well (becomes more important with wider lines). See ?par and scroll down to lend for options/details. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- project.org] On Behalf Of Philipp Pagel Sent: Monday, September 29, 2008 5:40 AM To: r-help at r-project.org Subject: Re: [R] histogram-like plot with two variables On Mon, Sep 29, 2008 at 04:02:05AM +0200, J?rg Gro? wrote:
Hi, I want to plot a binomial propability distribution. I know how to generate the data; x <- seq(from=0, to=14, by=1) y <- dbinom(x, 14, 0.7, log = FALSE) I tried: plot(x,y, type="h") but the bars are very thin -is there a way to define the width?
yes - the lwd parameter controls line width. E.g.:
plot(x,y, type='h', lwd=5)
This is the way I usually plot count data - I prefer this over
something
that looks like a normal histogram, because it reminds me that I am
looking at discrete values.
cu
Philipp
--
Dr. Philipp Pagel
Lehrstuhl f?r Genomorientierte Bioinformatik
Technische Universit?t M?nchen
Wissenschaftszentrum Weihenstephan
85350 Freising, Germany
http://mips.gsf.de/staff/pagel
______________________________________________ R-help at r-project.org 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.