[R] Barplot - Beginners Question

Duncan Murdoch murdoch.duncan at gmail.com
Mon Oct 5 01:39:54 CEST 2015


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

On 04/10/2015 3:31 PM, Jutta Wrage wrote:
> Hi!
> 
> According to this I tried to create a barplot:
> 
> https://de.wikibooks.org/wiki/GNU_R:_barplot
> 
> Input Data (Tab delimeted)
> 
> Range   Anzahl  Prozent 36-40   12      1.92 41-45   21      3.36 
> 46-50   48      7.68 51-55   87      13.92 56-60   92      14.72 
> 61-65   131     20.96 66-70   67      10.72
> 
> I read the table using this command:
>> datentabelle <- read.table( "stats-test.txt", header = TRUE, sep
>> = "\t", dec = ".", row.names=1) datentabelle
> Anzahl Prozent 36-40     12    1.92 41-45     21    3.36 46-50
> 48    7.68 51-55     87   13.92 56-60     92   14.72 61-65    131
> 20.96 66-70     67   10.72 71-75     52    8.32 76-80     25
> 4.00
>> is.data.frame(datentabelle)
> [1] TRUE
>> 
> 
> Looking ate the table it looks like VADeaths
> 
> Then I try to plot as described in wikibooks
> 
>> barplot(datentabelle[,1], main= "Altersverteilung")
> 
> The plot I get looks lie that using VADeaths with one difference: I
> do not ret the rownames in my table as labels for the bars
> 
> So what am I missing?

Your data is a dataframe, VADeaths is a matrix.  For some dim
historical reason, pulling a column from a matrix keeps the row names,
but pulling a column from a dataframe doesn't.

You'll get what you want if you use as.matrix(datentabelle)[,1]
instead of datentabelle[,1].

Duncan Murdoch

> 
> I expect something like I get from
>> barplot(VADeaths[,1], main= "Altersverteilung")
> 
> Jutta
> 
> 
> 
> -- http://www.witch.westfalen.de
> 
> 
> 
> ______________________________________________ R-help at r-project.org
> mailing list -- To UNSUBSCRIBE and more, see 
> 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.
> 

-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2
Comment: GPGTools - https://gpgtools.org

iQEcBAEBCgAGBQJWEbjKAAoJEHE2Kz23YMZyx8sH/iX62bx7uRmXHFSbJbYMBUxf
+WTDZyO0nQFq8fLwti2NWuTchWvu/hBoIWheIGPCe7xF9ApoJydHmAc4DIf6xoqT
nngQS2F9mGyjgfMagnH68pvMI/W8bwOW3VIJ2nb5nhpSPF/yQZsKLewcyI+L1uiZ
uDPeol7Ig6ij7amGnz4haa1g7wRhUp/mAcFn8gBuDOh5Y4vFpqdba1NcRUQP5Kj8
4x+wN4eKqX0uT2IV0GkGfNT1R4sYR6g+Ardml+vQZ5E+fRrZxi6SoOSRWgptiBAM
cqad7Mfll6RdPWTVCwTlctTYw0arIzNsMaUoG7E+QlcbKviMCNx8IRZUScJP/5c=
=B1u9
-----END PGP SIGNATURE-----



More information about the R-help mailing list