如何在不删除y轴刻度线的情况下隐藏水平网格线?

时间:2019-10-24 17:47:16

标签: r ggplot2

我想删除水平网格线,但保持垂直网格线。我也想在x和y轴上都保持刻度。

这是我的代码以及到目前为止我尝试过的操作:

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

1 个答案:

答案 0 :(得分:1)

您的出门率达到了95%。网格有两组线-主线和副线。您删除了一半的水平网格(panel.grid.minor.y)。要删除另一半,请添加panel.grid.major.y = element_blank()。要将刻度添加到x和y轴,请添加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")