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