is it possible to make a ggplot2 extension (ex. geom_smooth) that converts the existing xy axes into log10 scales automatically?
here's a reprex for example
set.seed(11) # generate random data
method1 = c(rnorm(19,0,1),2.5)
method2 = c(rnorm(19,0,1),2.5)
Subject <- rep(paste0('S',seq(1:20)), 2)
Data <- data.frame(Value = matrix(c(method1,method2),ncol=1))
Method <- rep(c('Method 1', 'Method 2'), each = length(method1))
df_corr <- data.frame(first = method1, second = method2) # used for correlation
ggplot(data = df_corr, mapping = aes(x = first, y = second)) +
geom_smooth() + # line 2
scale_x_continuous(trans = 'log10') + # line 3
scale_y_continuous(trans = 'log10') # line4
Instead I would like to create a ggplot2 extension function (that receives all the aesthetics defined by ggplot2()
) that does what lines 2-4 at once using ggproto.
You can implement your own function in the following manner:
To create your own
ggplot
function, you need to useggproto
, and the process is outlined here.