[R] Line in hist count

Adams, Jean jvadams at usgs.gov
Mon Sep 28 20:30:51 CEST 2015


I'm not sure what you want when you refer to the "last value of f", but
perhaps this will help you out.  I simplified your example since the other
parts of the code you submitted (par, grid, title, etc.) do not have
anything to do with your question.

# some fake data for f
f <- rnorm(20)

# save the counts using default breaks
fhist <- hist(f, plot=FALSE)

# calculate the proportion
x <- fhist$counts/sum(fhist$counts)

# plot the results, and save the y values
b <- barplot(x, horiz=TRUE)

# add text to the bars
text(x, b, b, pos=2)

Jean


On Sun, Sep 27, 2015 at 4:51 PM, bgnumis bgnum <bgnumis at gmail.com> wrote:

> Hi, all
>
> I have discovered that with abline(h=dataf,col="red") can add a line as I
> want in this plot
>
> fhist<-hist(f,plot=FALSE)
> par(mar=c(6,0,6,6))
> barplot(fhist$counts/ sum(fhist$counts),axes=FALSE,
> space=0,horiz=TRUE,col="lightgray")
> grid()
> title("Marginal Distribution CDS vs. Ibex",font=4)
> abline(h=dataf,col="red")
>
> The thing is:
>
> ¿How can I display the associated fhist$counts/ sum(fhist$counts on the
> last value of f?
>
> 2015-09-26 23:31 GMT+02:00 bgnumis bgnum <bgnumis at gmail.com>:
>
> > Hi all,
> >
> > Several time ago I used to work with R, now I´m returning to study and
> > work and searching old file I see that I used this code:
> >
> >
> > gfhist<-hist(gf,plot=FALSE)
> >
> > par(mar=c(6,0,6,6))
> >
> > barplot(gfhist$counts,axes=FALSE, space=0,horiz=TRUE,col="lightgray")
> >
> > grid()
> >
> > title("Marginal Distribution Lagged",font=4)
> >
> > The thing is I would line to plot a bar (horizontal and thing bar that
> > will be placed on the last gf data but on the barplot
> >
> > ¿Do you think is it possible? gf is a matrix.
> >
> >
> >
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list