[英]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.