2

I want to remove horizontal grid lines but keep vertical ones. I also want to keep ticks on both x and y axis.

This is my code and what I tried so far:

df <- data.frame("prop" = c(102.73,260.65), "Name" = c("All Genes","RG Genes"))
p<-ggplot(data=df, aes(x=Name, y=prop,fill=Name)) +
  geom_bar(stat="identity")+
  labs(x="", y = "Proportion of cis EQTLs")+
  scale_fill_brewer(palette="Greens") + 
  theme_minimal()+
  theme(legend.position = "none",panel.grid.minor.y = element_blank())
p + annotate("text", x = 1.5, y = 280, label = "p = XXXXXX", size = 3.5) + 
    annotate("rect", xmin = 1, xmax = 2, ymin = 270, ymax =270, alpha=1,colour = "black")

natej
  • 128
  • 7
anamaria
  • 341
  • 3
  • 11

1 Answers1

2

You were 95% of the way there. The grid has two sets of lines--major and minor. You removed half of the horizontal grid (panel.grid.minor.y). To remove the other half add panel.grid.major.y = element_blank(). To add ticks to both the x and y axis add axis.ticks = element_line()

df <- data.frame("prop" = c(102.73,260.65), "Name" = c("All Genes","RG Genes"))

p <- ggplot(data = df, aes(x = Name, y = prop, fill = Name)) +
  geom_bar(stat = "identity") +
  labs(x = "", y = "Proportion of cis EQTLs") +
  scale_fill_brewer(palette="Greens") + 
  theme_minimal() +
  theme(legend.position = "none",
        panel.grid.major.y = element_blank(),
        panel.grid.minor.y = element_blank(),
        axis.line = element_line(),
        axis.ticks = element_line())

p + annotate("text", x = 1.5, y = 280, label = "p = XXXXXX", size = 3.5) + 
  annotate("rect", xmin = 1, xmax = 2, ymin = 270, ymax =270, alpha=1,colour = "black")

natej
  • 128
  • 7
  • Thank you so much, is there is a way to see y axis, and not have this 3 numbers be in the air? Also would be good to have x axis – anamaria Oct 24 '19 at 18:55
  • No problem. Yes, to add an axis line you use `axis.line` if you wanted to only specify one you could use `axis.line.x` or `axis.line.y`. Since you want both you can omit the x/y which will add both. Edited answer to add axis line. – natej Oct 24 '19 at 19:04