1

I have this 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

and I used this code:

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()

and I obtained this graphic:

enter image description here

But I would like to wright additional information in the captions, for example the values 665 and 513.8. I would like to put "Production = 665 kg" and "Production = 513.8 kg", in the same place, but with the additional information. I tried this:

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

But didn't work.

Curious G.
  • 838
  • 8
  • 23

1 Answers1

1

You need to add paste0 after rounding the Mean since it doesn't makes sense to round character values.

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 ()

enter image description here

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213