出于发布目的,我的老板要求我将条形图标签上方的“0”替换为“n/a”。我运行的代码:
geom_text(aes(label = round(variable, digits = 0), , vjust = -0.5, colour = "black")
我得到的:
tmb3ates1#
以下是使用内置数据的示例:
library(tidyverse) labeldata=data.frame(cut=c('Fair','Good','Very Good','Premium','Ideal'), table=c(NA,300000,750000,900000,1250000), label=as.character(c(0,300000,750000,900000,1250000))) %>% mutate(table=ifelse(is.na(table),0,table)) labeldata ggplot(data = diamonds) + geom_col(aes(x=cut,y=table)) + geom_text(data = labeldata, aes(x=cut,y=table,label=label))
1条答案
按热度按时间tmb3ates1#
以下是使用内置数据的示例: