I want to draw an x axis with two scales like the picture below:
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With