Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I anchor one side of axis limits? [duplicate]

Tags:

r

ggplot2

I have a data frame of positive x and y values that I want to present as a scatterplot in ggplot2. The values are clustered away from the point (0,0), but I want to include the x=0 and y=0 lines in the plot to show overall magnitude. How can I do this?

set.seed(349)
d <- data.frame(x = runif(10, 1, 2), y = runif(10, 1, 2))
ggplot(d, aes(x,y)) + geom_point()

Plot without (0,0)

But what I want is something roughly equivalent to this, without having to specify both ends of the limits:

ggplot(d, aes(x=x, y=y)) + geom_point() + 
  scale_x_continuous(limits = c(0,2)) + scale_y_continuous(limits = c(0,2))

Plot with (0,0)

like image 678
Blue Magister Avatar asked Jul 24 '14 20:07

Blue Magister


1 Answers

One option is to just anchor the x and y min, but leave the max unspecified

ggplot(d, aes(x,y)) + geom_point() +
  scale_x_continuous(limits = c(0,NA)) + 
  scale_y_continuous(limits = c(0,NA))
like image 138
MrFlick Avatar answered Sep 30 '22 08:09

MrFlick