R barplot水平,y轴缺失值

时间:2013-11-10 11:30:48

标签: r plot scale histogram bar-chart

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轴(价格)没有显示任何值。

1 个答案:

答案 0 :(得分:1)

你可以试试这个:

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)

enter image description here