Dear all,
I have a dataset. I want to make barplot from this data.
Zero1 <- "
V1 V2 V3 V4 V5 V6 V7 V8 V9
1 1 0 0 0 1 0 0 0 Positive
2 0 0 1 0 1 0 1 1 Negative
3 0 0 1 0 0 0 1 1 Positive
4 0 1 0 1 1 1 0 1 Negative
5 0 0 1 0 1 1 0 0 Positive
6 0 1 0 0 1 1 1 1 Negative
7 1 0 1 1 1 1 1 1 Negative
8 0 0 0 0 1 0 0 1 Negative
9 0 1 1 1 1 0 0 1 Negative
10 0 0 0 1 1 0 1 0 Positive
11 0 0 0 0 1 0 0 1 Negative
12 0 0 1 1 1 1 1 0 Positive
13 0 1 1 0 1 1 1 1 Negative"
z1 <- read.table(textConnection(Zero1), header=TRUE)
z1
str(z1)
A simple way I can use mosaic plot
mosaicplot(table(z1))
library(vcd)
mosaic(table(z1))
I have tried to learn ?xtabs ?table and ?ftable but I can't figure out.
I need a barplot for all variables and the result maybe like
| | | |
| | | | | | | | |
|pos|neg| |pos|neg| |pos|neg|
| | | | | | | | |
--------- --------- ---------
v1 v2 v3 .... v7 v8
Thanks you for any helps.
Regards, Muhammad Subianto
barplot(t(sapply(split(z1[,1:8], z1$V9),colSums)), beside=T) ------------------------------------------------------------------- Jacques VESLOT CNRS UMR 8090 I.B.L (2?me ?tage) 1 rue du Professeur Calmette B.P. 245 59019 Lille Cedex Tel : 33 (0)3.20.87.10.44 Fax : 33 (0)3.20.87.10.31 http://www-good.ibl.fr ------------------------------------------------------------------- Muhammad Subianto a ?crit :> Dear all, > I have a dataset. I want to make barplot from this data. > Zero1 <- " > V1 V2 V3 V4 V5 V6 V7 V8 V9 > 1 1 0 0 0 1 0 0 0 Positive > 2 0 0 1 0 1 0 1 1 Negative > 3 0 0 1 0 0 0 1 1 Positive > 4 0 1 0 1 1 1 0 1 Negative > 5 0 0 1 0 1 1 0 0 Positive > 6 0 1 0 0 1 1 1 1 Negative > 7 1 0 1 1 1 1 1 1 Negative > 8 0 0 0 0 1 0 0 1 Negative > 9 0 1 1 1 1 0 0 1 Negative > 10 0 0 0 1 1 0 1 0 Positive > 11 0 0 0 0 1 0 0 1 Negative > 12 0 0 1 1 1 1 1 0 Positive > 13 0 1 1 0 1 1 1 1 Negative" > > z1 <- read.table(textConnection(Zero1), header=TRUE) > z1 > str(z1) > > A simple way I can use mosaic plot > mosaicplot(table(z1)) > library(vcd) > mosaic(table(z1)) > > I have tried to learn ?xtabs ?table and ?ftable but I can't figure out. > I need a barplot for all variables and the result maybe like > > | | | | > | | | | | | | | | > |pos|neg| |pos|neg| |pos|neg| > | | | | | | | | | > --------- --------- --------- > v1 v2 v3 .... v7 v8 > > Thanks you for any helps. > Regards, Muhammad Subianto > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
Dear all, Many Thanks to Jacques VESLOT and Jim Lemon for their helps. Best, Muhammad Subianto #Jacques VESLOT barplot(t(sapply(split(z1[,1:8], z1$V9),colSums)), beside=T) #Jim Lemon barplot(sapply(z1[1:8],by,z1[9],sum),beside=TRUE) On this day 30/08/2006 11:43, Muhammad Subianto wrote:> Dear all, > I have a dataset. I want to make barplot from this data. > Zero1 <- " > V1 V2 V3 V4 V5 V6 V7 V8 V9 > 1 1 0 0 0 1 0 0 0 Positive > 2 0 0 1 0 1 0 1 1 Negative > 3 0 0 1 0 0 0 1 1 Positive > 4 0 1 0 1 1 1 0 1 Negative > 5 0 0 1 0 1 1 0 0 Positive > 6 0 1 0 0 1 1 1 1 Negative > 7 1 0 1 1 1 1 1 1 Negative > 8 0 0 0 0 1 0 0 1 Negative > 9 0 1 1 1 1 0 0 1 Negative > 10 0 0 0 1 1 0 1 0 Positive > 11 0 0 0 0 1 0 0 1 Negative > 12 0 0 1 1 1 1 1 0 Positive > 13 0 1 1 0 1 1 1 1 Negative" > > z1 <- read.table(textConnection(Zero1), header=TRUE) > z1 > str(z1) > > A simple way I can use mosaic plot > mosaicplot(table(z1)) > library(vcd) > mosaic(table(z1)) > > I have tried to learn ?xtabs ?table and ?ftable but I can't figure out. > I need a barplot for all variables and the result maybe like > > | | | | > | | | | | | | | | > |pos|neg| |pos|neg| |pos|neg| > | | | | | | | | | > --------- --------- --------- > v1 v2 v3 .... v7 v8 > > Thanks you for any helps. > Regards, Muhammad Subianto >
Try this. First we reduce the data to a frequency matrix and
then plot it using classic and then lattice graphics:
zm <- as.matrix(rowsum(z1[-9], z1[,9]))
barplot(zm, beside = TRUE, col = grey.colors(2))
legend("topleft", legend = levels(z1[,9]), fill = grey.colors(2))
library(lattice)
barchart(Freq ~ Var2, as.data.frame.table(zm),
groups = Var1, origin = 0, auto.key = TRUE)
On 8/30/06, Muhammad Subianto <msubianto at gmail.com>
wrote:> Dear all,
> I have a dataset. I want to make barplot from this data.
> Zero1 <- "
> V1 V2 V3 V4 V5 V6 V7 V8 V9
> 1 1 0 0 0 1 0 0 0 Positive
> 2 0 0 1 0 1 0 1 1 Negative
> 3 0 0 1 0 0 0 1 1 Positive
> 4 0 1 0 1 1 1 0 1 Negative
> 5 0 0 1 0 1 1 0 0 Positive
> 6 0 1 0 0 1 1 1 1 Negative
> 7 1 0 1 1 1 1 1 1 Negative
> 8 0 0 0 0 1 0 0 1 Negative
> 9 0 1 1 1 1 0 0 1 Negative
> 10 0 0 0 1 1 0 1 0 Positive
> 11 0 0 0 0 1 0 0 1 Negative
> 12 0 0 1 1 1 1 1 0 Positive
> 13 0 1 1 0 1 1 1 1 Negative"
>
> z1 <- read.table(textConnection(Zero1), header=TRUE)
> z1
> str(z1)
>
> A simple way I can use mosaic plot
> mosaicplot(table(z1))
> library(vcd)
> mosaic(table(z1))
>
> I have tried to learn ?xtabs ?table and ?ftable but I can't figure out.
> I need a barplot for all variables and the result maybe like
>
> | | | |
> | | | | | | | | |
> |pos|neg| |pos|neg| |pos|neg|
> | | | | | | | | |
> --------- --------- ---------
> v1 v2 v3 .... v7 v8
>
> Thanks you for any helps.
> Regards, Muhammad Subianto
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
Muhammad Subianto wrote:> ... > I have tried to learn ?xtabs ?table and ?ftable but I can't figure out. > I need a barplot for all variables and the result maybe like > > | | | | > | | | | | | | | | > |pos|neg| |pos|neg| |pos|neg| > | | | | | | | | | > --------- --------- --------- > v1 v2 v3 .... v7 v8 >barplot(sapply(z1[1:8],by,z1[9],sum),beside=TRUE) Jim