R 如何在条形图lan中为每个条形图添加标签

R 如何在条形图lan中为每个条形图添加标签,r,R,我想用Y值为每个条添加标签 您可以使用text()属性将y值添加到新行上的barplot(),如下所示: library(tibble) df <- data_frame(month=month.abb[1:12], Freq=c(12, 11, -5, 3, 4, 1, 43, 5,60,34,-4,3)) p<-barplot(df$Freq, col = rainbow(20), ylim=c(-10,60), names.arg = df$month, space=0, a

我想用Y值为每个条添加标签


您可以使用
text()
属性将y值添加到新行上的
barplot()
,如下所示:

library(tibble)
df <- data_frame(month=month.abb[1:12], Freq=c(12, 11, -5, 3, 4, 1, 43, 5,60,34,-4,3))
p<-barplot(df$Freq, col = rainbow(20), ylim=c(-10,60), names.arg = df$month, space=0, axes=F)
xval = seq(-5, 60, 5)
axis(side = 2, at = xval, labels = FALSE, xpd=T)
axis(side = 2, at = xval, tick = FALSE, labels = xval, xpd=T)
text(p, df$Freq + 2*sign(df$Freq), labels=df$Freq, xpd=TRUE) #this is the line of your interest in regards to the value labels
库(TIBLE)

df您可以使用
text()
属性将y值添加到新行上的
barplot()
,如下所示:

library(tibble)
df <- data_frame(month=month.abb[1:12], Freq=c(12, 11, -5, 3, 4, 1, 43, 5,60,34,-4,3))
p<-barplot(df$Freq, col = rainbow(20), ylim=c(-10,60), names.arg = df$month, space=0, axes=F)
xval = seq(-5, 60, 5)
axis(side = 2, at = xval, labels = FALSE, xpd=T)
axis(side = 2, at = xval, tick = FALSE, labels = xval, xpd=T)
text(p, df$Freq + 2*sign(df$Freq), labels=df$Freq, xpd=TRUE) #this is the line of your interest in regards to the value labels
库(TIBLE)
df