[R] Creating a histogram from a frequency vector

Rui Barradas ru|pb@rr@d@@ @end|ng |rom @@po@pt
Wed Oct 9 18:58:40 CEST 2019


Here are 3 ways.

The first are almost the same, they use base graphics.

x <- 1:6
y <- c(73,53,42,67,41,50)

barplot(setNames(y, x))


names(y) <- x

And 3:

ggplot(data.frame(x, y), aes(x, y)) +

Hope this helps,

Rui Barradas

Às 16:12 de 09/10/19, Nick Wray via R-help escreveu:
> I have a vector like say 73,53,42,67,41,50 where these numbers are the number of occurrences of the data values 1,2,3,4,5,6 - so in essence I have the frequency bit from the hist() function.  I can't see an elegant way (there are clearly messy workarounds like generating a vector of 73 1's, 53 2's etc) of creating a histogram from this data set.  Is there one?
> Thanks Nick Wray
> 	[[alternative HTML version deleted]]
> ______________________________________________
> R-help using 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.

More information about the R-help mailing list