Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I draw an x axis with two scales?

Tags:

r

I want to draw an x axis with two scales like the picture below:

enter image description here

like image 879
Rafael Avatar asked Nov 13 '12 04:11

Rafael


1 Answers

ggplot2 version can look like this:

library(ggplot2)

x = c(1,2,3,4,5, 10,20,30,40,50)
y = c(1,2,2,3,4, 2,1,3,5,5)
# You should introduce cond - condition to separate axises - by yourself
df = data.frame(x=x,y=y,cond=ifelse(x>5,"x2","x1"))

ggplot(df, aes(x,y,group=cond)) + geom_line() + geom_point(aes(shape=cond), size=4) + facet_grid(.~cond, scales="free_x")

Which produces this plot: enter image description here

like image 79
redmode Avatar answered Oct 04 '22 16:10

redmode