kassambara / ggpubr

'ggplot2' Based Publication Ready Plots

Home Page:https://rpkgs.datanovia.com/ggpubr/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

stat_cor() limitation in GGPLOT2

vmatli opened this issue · comments

Please briefly describe your problem and what output you expect.
I was using stat_cor() to report correlation between two sets of values in GGPLOT. There was a skew in the data so I used scale_x_continuous and scale_y_continuous to log transform the values. When I used the stat_cor() function it was providing values on transformed scale rather than untransformed scale. I understand that having a different R would cause confusion due to the pattern observed in the data but having the option to use transformed vs untransformed values could be beneficial.


Random Data

x<-rnorm(20000,25,4)

y<-rnorm(20000,17,2)

Make Dataframe

data<-data.frame(cbind(x,y))

Expected behavior

Untransformed scale plot

plot<-ggplot(data,aes(x,y))+
geom_point()+
stat_cor()

plot

Actual behavior

Transformed scale plot

plot_trans<-ggplot(data,aes(x,y))+
geom_point()+
stat_cor()+
scale_x_continuous(trans="log")+
scale_y_continuous(trans="log")

plot_trans

Steps to reproduce the problem

If there was an option in stat_cor to show r values on transformed scale vs untransformed scale it would make the whole process more efficient. I dont know how to go about fixing the issue so maybe someone can pitch in.

Thanks