All, Consider:
BagA <- c(-1000,10,10,10,10,10,10,
10,20,20,20,20,20,20,30,
30,40,40,50,60)
BagB <- c(10,20,30,30,40,40,50,50,
50,50,50,50,60,60,60,60,
60,60,60,1000)
layout(c(2,1))
barplot(table(BagB))
barplot(table(BagA))
At this point, I'd like to arrange the plots so that the 10-bars are
aligned, the 20-bars are aligned, etc. So, I started thinking, how do I add
an entry to a table? I tried:
tmp <- table(BagA)
tmp[8] <- 0
names(tmp)[8] <- "1000"
barplot(tmp)
But I got this error:
> source('~/.active-rstudio-document')
Error in barplot.default(tmp) : 'height' must be a vector or a matrix
Makes me think I should not be telling my students to do:
barplot(table(BagA))
As it might give future troubles.
1. What am I missing?
2. Can anyone propose an alternate strategy for aligning by tables?
Thanks
David Arnold
College of the Redwoods
--
View this message in context:
http://r.789695.n4.nabble.com/Aligning-barplot-tp4641356.html
Sent from the R help mailing list archive at Nabble.com.
I was able to do this, but kinda painful:
BagA <- c(-1000,10,10,10,10,10,10,
10,20,20,20,20,20,20,30,
30,40,40,50,60)
BagB <- c(10,20,30,30,40,40,50,50,
50,50,50,50,60,60,60,60,
60,60,60,1000)
tblA <- table(BagA)
tblAnames <- names(tblA)
tblA <- as.vector(tblA)
tblA[8] <- 0
names(tblA) <- c(tblAnames,"1000")
tblB <- table(BagB)
tblBnames <- names(tblB)
tblB <- as.vector(tblB)
tblB <- c(0,tblB)
names(tblB) <- c("-1000",tblBnames)
layout(c(2,1))
barplot(tblB)
barplot(tblA)
Any better ideas?
darnold wrote>
> All, Consider:
>
> BagA <- c(-1000,10,10,10,10,10,10,
> 10,20,20,20,20,20,20,30,
> 30,40,40,50,60)
>
>
> BagB <- c(10,20,30,30,40,40,50,50,
> 50,50,50,50,60,60,60,60,
> 60,60,60,1000)
>
> layout(c(2,1))
>
> barplot(table(BagB))
> barplot(table(BagA))
>
> At this point, I'd like to arrange the plots so that the 10-bars are
> aligned, the 20-bars are aligned, etc. So, I started thinking, how do I
> add an entry to a table? I tried:
>
> tmp <- table(BagA)
> tmp[8] <- 0
> names(tmp)[8] <- "1000"
>
> barplot(tmp)
>
> But I got this error:
>
>> source('~/.active-rstudio-document')
> Error in barplot.default(tmp) : 'height' must be a vector or a
matrix
>
> Makes me think I should not be telling my students to do:
>
> barplot(table(BagA))
>
> As it might give future troubles.
>
> 1. What am I missing?
>
> 2. Can anyone propose an alternate strategy for aligning my tables?
>
> Thanks
>
> David Arnold
> College of the Redwoods
>
--
View this message in context:
http://r.789695.n4.nabble.com/Aligning-barplot-tp4641356p4641357.html
Sent from the R help mailing list archive at Nabble.com.
darnold wrote> > All, Consider: > > BagA <- c(-1000,10,10,10,10,10,10, > 10,20,20,20,20,20,20,30, > 30,40,40,50,60) > > BagB <- c(10,20,30,30,40,40,50,50, > 50,50,50,50,60,60,60,60, > 60,60,60,1000) > > layout(c(2,1)) > > barplot(table(BagB)) > barplot(table(BagA)) > > At this point, I'd like to arrange the plots so that the 10-bars are > aligned, the 20-bars are aligned, etc. So, I started thinking, how do I > add an entry to a table? I tried: > > tmp <- table(BagA) > tmp[8] <- 0 > names(tmp)[8] <- "1000" > > barplot(tmp) > > But I got this error: > >Try using t(tmp) when plotting. When you started mucking with that table-object, it got converted (effectively) to a one row matrix (even though it retained it "table"-class attribute) and you need to make it a one column matrix to get the desired results with barplot().> tmpB <- table(BagB) > tmpB <- c(0, tmpB) > names(tmpB) <- c(-1000, names(table(BagB)) )> barplot( t(tmpB) ) > barplot( t(tmp) )-- David (W.) -- View this message in context: http://r.789695.n4.nabble.com/Aligning-barplot-tp4641356p4641358.html Sent from the R help mailing list archive at Nabble.com.
Hmmm....
This worked this time. And I didn't use the transform t.
BagA <- c(-1000,10,10,10,10,10,10,
10,20,20,20,20,20,20,30,
30,40,40,50,60)
BagB <- c(10,20,30,30,40,40,50,50,
50,50,50,50,60,60,60,60,
60,60,60,1000)
tblA <- table(BagA)
tblA <- c(tblA,0)
names(tblA) <- c(names(table(BagA)),"1000")
tblB <- table(BagB)
tblB <- c(0,tblB)
names(tblB) <- c("-1000",names(table(BagB)))
layout(c(2,1))
barplot(tblB, main="Bag B")
barplot(tblA, main="Bag A")
D.
David Winsemius wrote>
>
> darnold wrote
>>
>> All, Consider:
>>
>> BagA <- c(-1000,10,10,10,10,10,10,
>> 10,20,20,20,20,20,20,30,
>> 30,40,40,50,60)
>>
>> BagB <- c(10,20,30,30,40,40,50,50,
>> 50,50,50,50,60,60,60,60,
>> 60,60,60,1000)
>>
>> layout(c(2,1))
>>
>> barplot(table(BagB))
>> barplot(table(BagA))
>>
>> At this point, I'd like to arrange the plots so that the 10-bars
are
>> aligned, the 20-bars are aligned, etc. So, I started thinking, how do I
>> add an entry to a table? I tried:
>>
>> tmp <- table(BagA)
>> tmp[8] <- 0
>> names(tmp)[8] <- "1000"
>>
>> barplot(tmp)
>>
>> But I got this error:
>>
>>
>
> Try using t(tmp) when plotting. When you started mucking with that
> table-object, it got converted (effectively) to a one row matrix (even
> though it retained it "table"-class attribute) and you need to
make it a
> one column matrix to get the desired results with barplot().
>
>> tmpB <- table(BagB)
>> tmpB <- c(0, tmpB)
>> names(tmpB) <- c(-1000, names(table(BagB)) )
>
>> barplot( t(tmpB) )
>> barplot( t(tmp) )
>
>
> --
> David (W.)
>
--
View this message in context:
http://r.789695.n4.nabble.com/Aligning-barplot-tp4641356p4641359.html
Sent from the R help mailing list archive at Nabble.com.