Frage

Ich bin nach einer Möglichkeit, Etiketten hinzuzufügen, das heißt absolute Werte, in ein gestapeltes Balkendiagramm, das die Grund Plotfunktionen von R. Die Etiketten verwenden, sollten innerhalb der gestapelte Balken sein.

Danke!

War es hilfreich?

Lösung

barplot die Mitte x-Position der Stäbe zurückkehren, so dass Sie könnte

mydata <- matrix(c(10, 21, 22, 33, 45, 23, 22, 43, 33), nrow=3)

# b will contain the x midpoints of the bars
b <- barplot(mydata)

# This will write labels in the middle of the bars, horizontally and vertically
text(b, colMeans(mydata), c("Label1", "Label2", "Label3"))

# This will write labels in the middle of the middle block
text(b, mydata[1,]+mydata[2,]/2, c("LabelA", "LabelB", "LabelC"))

EDIT: Re-Lektüre Ihrer Frage, ich denke, das ist das, was Sie wollen (oder vielleicht auch nicht, aber ich werde es schreiben sowieso: D)

# Find the top y position of each block 
ypos <- apply(mydata, 2, cumsum)
# Move it downwards half the size of each block
ypos <- ypos - mydata/2
ypos <- t(ypos)

text(b, ypos, mydata)

Andere Tipps

Wie wäre es die einfache Funktion text()?

Sie können einfach einen String hinzufügen, wo immer Sie wollen, zum Beispiel:

text (x = ..., y = ..., labels = c("foo bar 1000"))

Vielleicht können Sie die barp Funktion der plotrix Paket

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top