1

代码:

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

4

1 回答 1

2

你可以试试这个:

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)

在此处输入图像描述

于 2013-11-10T12:13:52.147 回答