繁体   English   中英

R条形图水平,y轴缺少值

[英]R barplot horizontal, y axis missing values

R代码:

vp2 <- function(symbol){
  df = data.frame(Date=index(symbol), Adjusted=symbol$Adjusted, Volume=symbol$Volume)
  dt <- as.data.table(unique(df,by=Date))
  vol <- aggregate(cbind(Volume) ~ Adjusted, sum, data=dt)
  hmatrix <- as.matrix(vol$Volume)
  par(bg=NA)
  colnamesbarplot <- c("Adjusted","Volume")
  options(scipen=50,digits=10)
  barplot(hmatrix,beside=TRUE,horiz=TRUE,axes=TRUE,legend.text=TRUE,xlab="Volume",ylab="Price")
  return(vol)
}

样本数据(df)的片段:

    Date    Adjusted    Volume
1   2013-10-29  35.41   2333100
2   2013-10-30  34.85   5929200
3   2013-10-31  34.69   5100200
4   2013-11-01  34.13   9774900
5   2013-11-04  34.04   4571600
6   2013-11-05  33.67   6565300
7   2013-11-06  34.19   9905800
8   2013-11-07  33.97   4754500
9   2013-11-07  33.97   4754500
10  2013-11-08  34.01   3722200

结果条形图

问题-问题是y轴(价格)未显示任何值。

您可以尝试以下方法:

barplot(hmatrix, beside = TRUE, horiz = TRUE, xlab = "Volume", ylab = "")
axis(side = 2, at = seq_along(hmatrix) + 0.5, labels = vol$Adjusted, las = 2)
mtext(text = "Price", side = 2, line = 4)

在此处输入图片说明

暂无
暂无

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

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