Adding Additional Y-Axis in R with ggplot2 -
let's have following (x0,y0) data have plotted (the y0-axis plotted on left-hand side):
x0,y0 ----- 500,1 200,3 ...
further, have set of data (x1,y1) given as:
x1 y1 ----- 1.5,1 3.2,2 ...
i wanting add addition y1-axis on right-hand side, have x1 break points , y1 labels. x1 , y0 on same scale, 2 datasets of different lengths, , there no formula 1 can use derive x1 y0.
thanks
it's not entirely clear you're looking for. this?
df1 <- data_frame(x0 = c(500, 300), y0 = c(1, 3)) df2 <- data_frame(x1 = c(1.5, 3.2), y1 = c(1, 2)) ggplot(df1, aes(x0, y0)) + geom_point() + scale_y_continuous(expand = c(0.5,0.5), sec.axis = sec_axis(trans = . ~ ., breaks = df2$x1, labels = df2$y1))
Comments
Post a Comment