R 如何在ggplot2中的图形中写入附加标题?

R 如何在ggplot2中的图形中写入附加标题?,r,ggplot2,geom-text,R,Ggplot2,Geom Text,我有以下数据: Animal Age GC production Sire 1 220 5 945 1 2 246 5 870 1 3 210 5 430 2 4 270 5 415 2 5 225 6 750 1 6 198 6 730 1 7 227 6 280 2 8 221 6 295 2 我使用了这个代码: data=read.xlsx("arquivo.xlsx",1) data.1 = data %>%

我有以下数据:

Animal  Age GC  production  Sire
1   220 5   945 1
2   246 5   870 1
3   210 5   430 2
4   270 5   415 2
5   225 6   750 1
6   198 6   730 1
7   227 6   280 2
8   221 6   295 2
我使用了这个代码:

data=read.xlsx("arquivo.xlsx",1)

data.1 = data %>%
  group_by(GC) %>%
  dplyr::summarize(Mean = mean(na.omit(production)))

tiff("exemplo.tiff", width =10 , height =6 , units = 'in', res = 400, compression = 'none')
ggplot(data.1, aes(x=GC, y=Mean)) + 
  geom_bar(stat="identity", width=0.5)  +
  scale_y_continuous(breaks = round(seq(min(0), max(700), by = 100), digits=2),limits=c(0,700))+
  geom_text(aes(label = round(Mean, 1)), position = position_dodge(0.9), vjust = -0.3)  +
  geom_hline(yintercept=513.75, linetype="dashed", color = "red")+
  labs(x = "GC" ,y="Production") + 
  labs(subtitle="General", title= "Production kg") + 
  theme ()
dev.off()
我得到了这张图:

但我想在标题中添加更多信息,例如值665和513.8。我想把 “产量=665千克”和“产量=513.8千克”,在同一地点,但附有附加信息。我试过这个:

geom_text(aes(label = round(paste0("Production = "Mean, 1, paste0("kg"))), position = position_dodge(0.9), vjust = -0.3)

但是没有起作用

您需要在
round
之后添加
paste0
,因为
Mean
round
字符值没有意义

library(ggplot2)

ggplot(data.1, aes(x=GC, y=Mean)) + 
  geom_bar(stat="identity", width=0.5)  +
  scale_y_continuous(breaks = round(seq(min(0), max(700), by = 100),
                     digits=2),limits=c(0,700))+
  geom_text(aes(label = paste0("Production = ", round(Mean, 1), " kg")), 
                position = position_dodge(0.9), vjust = -0.3)  +
  geom_hline(yintercept=513.75, linetype="dashed", color = "red")+
  labs(x = "GC" ,y="Production") + 
  labs(subtitle="General", title= "Production kg") + 
  theme ()