0

When plotting a graph where y has negative values, is it possible to plot the x-axis line, tick marks and labels at y=0?

In the example below the x-axis is plotted at y=-10, the lower limit of the y-axis.

I could use + geom_abline(intercept=0, slope=0)to draw a line at y=0 but that's all.

data1<-as.data.frame(1:5)
data1[,2]<-as.data.frame(c(-8,-2,2,6,10))

colnames(data1)<-c("x","y")
ggplot(data1, aes(x=x)) + 
  geom_line(aes(y = y, colour = "y"), size=0.61, colour="black") + 
  xlab("X axis lab") + ylab("Y axis lab") +
  theme_bw() + theme(legend.title = element_blank(),
                     legend.key = element_rect(fill=NA),
                     panel.border = element_blank(), 
                     axis.line = element_line(colour="black", size=0.25),
                     axis.ticks = element_line(size=0.25),
                     panel.grid.major = element_line(colour = "grey80", size=0.25),
                     panel.grid.minor = element_line(colour = "grey80", size=0.25)) +
  scale_x_continuous(expand = c(0, 0), limits=c(0,5)) + 
  scale_y_continuous(expand = c(0, 0), limits=c(-10,10)) +
  ggtitle("Title")
Sven Hohenstein
  • 80,497
  • 17
  • 145
  • 168
user2568648
  • 3,001
  • 8
  • 35
  • 52
  • 1
    I suggest you switch to the base graphics system. It's really difficult (i.e., needs hacking with grid functions) with ggplot2 to have an axis inside the plot. – Roland Dec 19 '14 at 09:12
  • OK thanks, having seen the complex workaround I think I'll stick to `plot` – user2568648 Dec 19 '14 at 09:19

0 Answers0