Aditya Sihag
Aditya Sihag

Reputation: 5167

R histogram plot controlling x-axis values

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

Answers (3)

user1972382
user1972382

Reputation:

Try to use this:

# replicate each element in x y-times
z <- rep(x,y)
hist(z)

Upvotes: 3

user20650
user20650

Reputation: 25844

# create df with required frequency
m<-unlist(mapply(rep,x,y))
#check
table(m)
hist(m)

Upvotes: 0

Prasanna Nandakumar
Prasanna Nandakumar

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

Related Questions