Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

Error in annotate when trying to indicate the statistically significant difference in bar graph in ggplot

$
0
0

my code looks like this:

p <- ggplot(data = df, aes(x = Name, y = prop, fill = Name)) +
  geom_bar(stat = "identity") +
  labs(x = "", y = "EQTL / gene") +
  scale_fill_brewer(palette="Greens",name = "Number of cis EQTL") + 
  theme_classic()+
  theme(panel.grid.major.x = element_line(size = 0.1, color = "grey"),
        panel.grid.major.y = element_blank(),
        panel.grid.minor = element_blank()
  )

p+geom_path(x=c(1,1,2,2),y=c(0.85,0.86,0.86,0.85))+
  annotate("text",x=1.5,y=1.2,label="p = 2e-16")

what I am trying to do is just to put a horizontal line between the middle points of those two bars above which would be written: p = 2e-16

But when I run the code I get this error:

Error in annotate("text", x = 1.5, y = 1.2, label = "p = 2e-16") : 
  unused arguments (x = 1.5, y = 1.2, label = "p = 2e-16")

enter image description here

df <- readr::read_table(' prop                          Name
1 0.85            All_Genes
2 1.00 Glucose_Response_Genes103')

SOLUTION:

p <- ggplot(data = df, aes(x = Name, y = prop, fill = Name)) +
  geom_bar(stat = "identity") +
  labs(x = "", y = "Proportion of eGenes") +
  scale_fill_brewer(palette="Greens",name = "Number of cis EQTL", labels = c("3124345", "26846")) + 
  theme_minimal() +
  theme(legend.position = "right",
        panel.grid.major.y = element_blank(),
        panel.grid.minor.y = element_blank(),
        axis.line = element_line(),
        axis.ticks = element_line())

p + ggplot2::annotate("text", x = 1.5, y = 1.2, label = "p < 2e-16", size = 3.5) +  
  ggplot2::annotate("rect", xmin = 1, xmax = 2, ymin = 1.1, ymax =1.1, alpha=0.3,colour = "black")

As @Axeman pointed out the issues was with: ggplot2::annotate

Still I should like to know how to edit this code and get smaller and more elegant bars?


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>