Reputation: 23
Year Balance TotalDeposits
1 18837.44 18000
2 39313.74 36000
3 61571.47 54000
4 85765.63 72000
5 112064.68 90000
6 140651.75 108000
7 171725.89 126000
8 205503.49 144000
9 242219.73 162000
10 282130.29 180000
11 325513.06 198000
I have matrix
I would like to create a grouped barchat where x axis takes year as categorial variable. And bar represents balace and total deposits for corresponding year.
please suggest basic barchat function rather than ggplot or lattice functions.
I am reading the data from .csv file.
What I have tried so far
d <- read.table(text="Year Balance TotalDeposits
1 18837.44 18000
2 39313.74 36000
3 61571.47 54000
4 85765.63 72000
5 112064.68 90000
6 140651.75 108000
7 171725.89 126000
8 205503.49 144000
9 242219.73 162000
10 282130.29 180000
11 325513.06 198000")
d <- do.call(rbind,d)
barplot(d , beside=TRUE)
Upvotes: 2
Views: 118
Reputation: 11441
I am not sure if this is exactly what you want...
# after reading in dataframe into d
m <- t(d)
barplot(m[2:3, ] , beside=TRUE, names.arg=m[1, ],
col=2:3, las=1, xlab="Year")
legend("topleft", legend=c("Balance", "TotalDeposits"), fill=2:3, box.col=NA)
Upvotes: 0
Reputation: 121598
For example:
mat <- as.matrix(t(d[,2:3]))
colnames(mat) <- d[,1]
barplot(mat , beside=TRUE,legend.text=TRUE,
args.legend=list(x=8))
Where d is :
d <- read.table(text="Year Balance TotalDeposits
1 18837.44 18000
2 39313.74 36000
3 61571.47 54000
4 85765.63 72000
5 112064.68 90000
6 140651.75 108000
7 171725.89 126000
8 205503.49 144000
9 242219.73 162000
10 282130.29 180000
11 325513.06 198000",header=TRUE)
Upvotes: 1