0
votes

I have the following two vectors

 x<-c(-525,-520,-515,-460,-455,-450);
 y<-c(6,20,976,20,16,78);

I would like to plot a histogram where y vector denotes the frequency and the x vector denotes the x-axis values

3

3 Answers

3
votes

Try to use this:

# replicate each element in x y-times
z <- rep(x,y)
hist(z)
1
votes
dat <- data.frame(x=c(-525,-520,-515,-460,-455,-450), y=c(6,20,976,20,16,78))
barplot(dat$y, names.arg=dat$x, ylim=c(5,80), ylab=" frequency", xlab="x- Value")
1
votes
# create df with required frequency
m<-unlist(mapply(rep,x,y))
#check
table(m)
hist(m)