Reputation: 5167
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
Upvotes: 0
Views: 719
Reputation:
Try to use this:
# replicate each element in x y-times
z <- rep(x,y)
hist(z)
Upvotes: 3
Reputation: 25844
# create df with required frequency
m<-unlist(mapply(rep,x,y))
#check
table(m)
hist(m)
Upvotes: 0
Reputation: 4335
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")
Upvotes: 1