1

I am having trouble in adding multiple line text in ggplot. No matter what may I try, it is not working. Either I received an error , or no results at all ,

I got errors Error: Aesthetics must be either length 1 or the same as the data (464): label, group

Error in as.integer(n) : cannot coerce type 'closure' to vector of type 'integer' In addition: Warning messages: 1: Only the first value of nrow will be used. 2: Coercing nrow to be an integer. 3: In sanitise_dim(nrow) : NAs introduced by coercion 4: nrow is missing or less than 1 and will be treated as NULL. 5: Coercing ncol to be an integer.

my tags are

my_tag <- c("Event1 - July 04", "Event2 - July 25", "Event3 - August 10", " Event4 - Sept 28" )

Here is my code

Preinstall1 <- ggplot(PreeventLong, aes(Minutes, value,color = variable, group=variable))+ 
  scale_color_manual(values=c( "grey7",  "gray48"))+  ##### for defining desireable colours 
  geom_blank()+
  geom_line(size = 0.8)+
  geom_text(aes(x = -Inf, y = Inf, label = my_tag, group = my_tag),
            size = 5,
            hjust = -0.5,vjust = 1.4,
            inherit.aes = FALSE)+
  ylab("Flow rate (m3/s)")+
  xlab("Time(minutes)")+
  theme(legend.title = element_blank(), legend.position = "top", 
        plot.background = element_rect(NULL), panel.background = element_blank(), 
        axis.line = element_line())+
facet_wrap(~ Event, scales = "free", label_value(my_tag))+
  theme(strip.background = element_rect(fill = "White"), 
        strip.text = element_text(size = 12, colour = "black", angle = 360))

I want to add more text on multiple lines in individual facet wrap, but failed to do so thus far, some help will be appreciated

Shah
  • 31
  • 5
  • 1
    you need to pass a named character vector into the `labeller` argument in `facet_wrap`, see [this](http://www.cookbook-r.com/Graphs/Facets_(ggplot2)/#modifying-facet-label-text) – EJJ May 31 '20 at 13:17
  • Does not worked, I trust there is no way you can actually write the text on charts in ggplot – Shah Jun 04 '20 at 11:22
  • that is different from your original question, can you clarify what your desired output is? also if you provide a small [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) it would make it easier for people to provide help – EJJ Jun 05 '20 at 13:50

0 Answers0