How to annotate an individual chart using facet_grid?

Asked

Viewed 54 times

-1

I’m using the function annotate to try to number a figure with facet_grid, but the number goes on the two axes y. How do I write on only one side? https://1drv.ms/x/s! Avi1orbh4c0tjiyruc0ouxkny5fg? e=B6w23z

library(readxl)
Dados <- read_excel("Dados.xlsx")
print(Dados)

require(tidyverse)
require(ggthemes)
graph <- ggplot(Dados,aes(x = Temp, y = Gly, shape = Accesion)) +scale_shape_manual("Biotypes", values = c(19, 5))+
  geom_point(stat = 'summary', fun.y = 'mean') +
  geom_errorbar(stat = 'summary', fun.data = 'mean_se', 
                width=.08, fun.args = list(mult = 1.96)) +scale_y_continuous(breaks = seq(0, 125, 25), limits = c(0, 125))+ 
  facet_grid( . ~ Year ) +annotate("text", x=0.5, y=125, label= "3") +
  labs(x = 'Harvesting time', y = 'Glyphosate')+
  theme_bw() +
  theme(
    axis.title = element_text(size = 10),
    axis.text = element_text(size = 10),
    text = element_text(family = 'Times'),
    legend.position = "Right", 
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank()
  )
graph
  • can create an MWE?

  • Hello Lucas, thank you for answering! I edited the question and inserted a figure to illustrate. I need to number the figure. However, with the annotate function the number goes in the two figures. I need the number 3 to be just on the left

  • we need a database to replicate your problem (the database you are using or an equivalent example). MWE is the English acronym for a minimum verifiable example. See instructions: https://answall.com/help/minimal-reproducible-example

  • I’m a beginner around here. I don’t know how to share the data, I took a print of them...

  • Can you please, edit the question with the departure of dput(Gly_72_HORAS) or, if the base is too large, dput(head(Gly_72_HORAS, 20))?

  • I attached the data to the on drive

  • If one of the answers below solved your problem and there was no doubt left, choose the one you liked the most and mark it as correct/accepted by clicking on the " " that is next to it, which also marks your question as solved. If you still have any questions or would like further clarification, feel free to comment.

Show 2 more comments

1 answer

1

One option is to create another data.frame, add only text coordinate information to it and use geom_text to write down. See:

graph<- ggplot(Dados,aes(x = Temp, y = Gly, shape = Accesion)) +scale_shape_manual("Biotypes", values = c(19, 5))+
  geom_point(stat = 'summary', fun.y = 'mean') +
  geom_errorbar(stat = 'summary', fun.data = 'mean_se', 
                width=.08, fun.args = list(mult = 1.96)) +scale_y_continuous(breaks = seq(0, 125, 25), limits = c(0, 125))+ 
  facet_grid( . ~ Year )
  
ann<-data.frame(Accesion="ECHCO-SR", Temp=factor("24 hours", levels=c("24 hours","72")),
                Gly=105, label="3", Year=factor("Year 1", levels = c("Year 1","Year 2")))

graph<- graph + geom_text(data = ann,label = "3")
  
graph<- graph + labs(x = 'Harvesting time', y = 'Glyphosate')+
  theme_bw() +
  theme(
    axis.title = element_text(size = 10),
    axis.text = element_text(size = 10),
    text = element_text(family = 'Times'),
    legend.position = "Right", 
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank()
  )
graph

Returns:

inserir a descrição da imagem aqui

  • Right. Thank you very much! And how would I change the coordinates? For example, I need number 3 to be in the upper left corner of Year 1...

  • is only you make the relevant change in data.frame Ann. I will edit the answer

  • Right. Thank you! In this case you can not adjust coordinates on the x-axis?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.