简体   繁体   English

控制X轴值的R直方图

[英]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 我想绘制一个直方图,其中y向量表示频率,x向量表示x轴值

Try to use this: 尝试使用此:

# replicate each element in x y-times
z <- rep(x,y)
hist(z)
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")
# create df with required frequency
m<-unlist(mapply(rep,x,y))
#check
table(m)
hist(m)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM