Ggplot2 - Axis Aesthetics

In ggplot2you can draw this second axis label by comparing the percentage of values ​​from X and Y.

enter image description here

Edit:

I have data.frame with two vars, both related and percentage. I want to show the evolution of V1 associated with V2; for example, how many percent of V2 do I need to get 20% of V1 (and vice versa).

V1   V2
0    0
0.03 0.0005
0.10 0.0015
0.13 0.0020
....
1    1

Now my problem is how can I make this inner axis on X and Y, showing the relationship between X and Y percent. Also how to set ggplot to use (0,0) as an intercept of the x and y axis?

+5
source share
1 answer

(geom_rect geom_text) ggplot2. , :

, :

df <- data.frame(A=sort(runif(20)), B=sort(runif(20)))
df <- rbind(df, c(1,1))

, "" (: ):

df_rect <- data.frame(xmin=c(0, median(df$A), -0.01, -0.01), xmax=c(median(df$A), 1, 0, 0), ymin=c(-0.01, -0.01, 0, median(df$B)), ymax=c(0, 0, median(df$B), 1), color=grey(c(0.7, 0.2)), alpha=c(0.8, 0.4, 0.8, 0.4))

- :

df_text <- data.frame(x=c(median(df$A)/2, median(df$A) + (1-median(df$A))/2, 0.05, 0.05), y=c(0.02, 0.02, median(df$B)/2, median(df$B) + (1-median(df$B))/2), label=rep('50%', 4))

:

ggplot(df, aes(A, B)) + geom_point() +
    geom_line() +
    geom_rect(data=df_rect, aes(xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax, fill=color, alpha=alpha), inherit.aes = FALSE) + scale_fill_grey() +
    geom_text(data=df_text, aes(x=x, y=y, label=label), inherit.aes = FALSE) + 
    theme_bw() + scale_y_continuous(limits=c(-0.01, 1), formatter='percent') + scale_x_continuous(limits=c(-0.01, 1), formatter='percent') + opts(legend.position="none")

geom_point , geom_line ( ). geom_rect " " geom_text . () ( : df_rext df_text), . theme_bw - , scale_continous 0 1, formatter.

: sample plot

, !

+8

All Articles