Ich habe einen Datenrahmen, die wie dieses aussieht:Wie können negative x-Achsenbrüche (Beschriftungen) des Balkendiagramms ggplot2 in positive umgewandelt werden?
df <- structure(list(gender = c("male", "male", "male", "female", "female",
"female", "male", "male", "male", "male", "male", "female", "female",
"female"), agegroup = c("-24", "25-34", "45-54", "-24", "25-34",
"35-44", "-24", "25-34", "35-44", "65-", "unknown", "-24", "25-34",
"35-44"), N = c(-2, -4, -1, 3, 4, 1, -3, -14, -1, -1, -2, 3,
3, 1), N2 = c(2, 4, 1, 3, 4, 1, 3, 14, 1, 1, 2, 3, 3, 1), location = c("here",
"here", "here", "here", "here", "here", "there", "there", "there",
"there", "there", "there", "there", "there")), .Names = c("gender",
"agegroup", "N", "N2", "location"), row.names = c(NA, 14L), class = "data.frame")
Ich brauchte einige der Ns in Negativen zu machen, weil ich eine „Pyramide“ machen wollte. Wie folgt:
ggplot(biofile2, aes(x = agegroup, y = N , fill = gender),color=gender) +
geom_bar(stat="identity", size=.3, position="identity")+
facet_wrap(~ location,ncol=2)+
coord_flip()
Es sieht aus wie ich es vorhatte. Alles, was übrig bleibt, ist, die -10 und -5 wieder in positive umzuwandeln. Gibt es eine Möglichkeit, dies zu tun, ohne das Aussehen der Handlung zu verändern?
@Axeman Dank! Gibt es eine Möglichkeit, die Labels programmatisch zu ändern, wenn nicht vorher bekannt ist, welche Labels es geben wird? – rdatasculptor
@Axeman, Wenn Sie dies als Antwort hinzufügen, akzeptiere ich es. Danke noch einmal! – rdatasculptor