问题
I have data in this form:

proprete.freq <- table(cnData$proprete)
proprete.freq.genre <-table(cnData$genre,cnData$proprete)

I am using these functions (barplot and pie) to plot the data:
barplot(proprete.freq.genre, col = heat.colors(length(rownames(proprete.freq.genre)))
, main="Proprete", beside = TRUE)
pie(proprete.freq, col=rainbow(3), names.arg=avis, main="Propreté")
Here is the result:


Question: How to include the value just on top of the barplots and below the categorical variables for the pie. Something like that:


回答1:
Here is a general approach:
pie
has a labels parameter so you can just use that, use\n
for a line break, and add text under the namebarplot
has a return value which are the x-coordinates of each bar, so just usetext
along with the data (for the y-coordinates), and usepos = 3
to put the label above that{x, y}
point.
ex:
par(mfrow = c(2, 1))
pie(1:3, labels = sprintf('%s\n%s%%', 1:3, round(1:3 / 6 * 100)))
bp <- barplot(VADeaths, beside = TRUE)
text(c(bp), c(VADeaths), labels = c(VADeaths), pos = 3, xpd = NA)

来源:https://stackoverflow.com/questions/28909843/include-values-to-the-barplot-and-pie-charts-in-r