Ich hoffe, dass das Folgende für Sie hilfreich sein wird.
Hier ist ein Datensatz mit den Daten der 10 größten besiedelten Länder:
df <- structure(list(Country = c("China", "India", "United States",
"Indonesia", "Brazil", "Pakistan", "Nigeria", "Bangladesh", "Russia",
"Mexico"), Population = structure(c(3L, 2L, 10L, 9L, 8L, 7L,
6L, 5L, 4L, 1L), .Label = c("130222815", "1342512706", "1388232693",
"143375006", "164827718", "191835936", "196744376", "211243220",
"263510146", "326474013"), class = "factor")), .Names = c("Country",
"Population"), row.names = 2:11, class = "data.frame")
Die df$Population
Variable ist ein factor
und die Bevölkerungswerte werden in den Faktorstufen gespeichert:
str(df)
'data.frame': 10 obs. of 2 variables:
$ Country : chr "China" "India" "United States" "Indonesia" ...
$ Population: Factor w/ 10 levels "130222815","1342512706",..: 3 2 10 9 8 7 6 5 4 1
Wir plotten können die Bevölkerungswerte wie folgt.
Zunächst wandeln wir die Ebenen von df$Population
in ein numerisches Array:
Pop <- as.numeric(as.character(df$Population))
str(Pop)
num [1:10] 1388232693 1342512706 326474013 263510146 211243220 ...
und wir die Bevölkerung Werte dann plotten barplot
mit:
par(mar=c(4,7,1,1))
options(scipen=9)
barplot(Pop, names=df$Country, yaxt = "n")
yticks <- pretty(Pop)
axis(2, yticks, las=2, labels = prettyNum(yticks, big.mark = ","))
Warum sind die Bevölkerung einen 'Faktorwerte '? Es kann besser sein, diese in Zahlen umzuwandeln. (sieht aus wie ein Datei lesen Problem das Komma-Format beachten) – bouncyball