I am having trouble understanding an R plotting script one of my coworkers provided me. I understand that ggplot can be used to transform data in the plotting routine, but I am looking for an alternate method to calculate the transform using other functions in r. For the data bwpeaks
structure(list(PROB = c(0.25, 0.116666666666667, 0.15, 0.366666666666667,
0.4, 0.133333333333333, 0.633333333333333, 0.5, 0.483333333333333,
0.516666666666667, 0.1, 0.3, 0.666666666666667, 0.9, 0.716666666666667,
0.466666666666667, 0.283333333333333, 0.583333333333333, 0.0833333333333333,
0.35, 0.416666666666667, 0.866666666666667, 0.6, 0.2, 0.75, 0.533333333333333,
0.933333333333333, 0.566666666666667, 0.816666666666667, 0.966666666666667,
0.433333333333333, 0.85, 0.95, 0.333333333333333, 0.8, 0.0666666666666667,
0.733333333333333, 0.883333333333333, 0.183333333333333, 0.0166666666666667,
0.7, 0.45, 0.266666666666667, 0.216666666666667, 0.616666666666667,
0.166666666666667, 0.916666666666667, 0.383333333333333, 0.683333333333333,
0.316666666666667, 0.05, 0.766666666666667, 0.233333333333333,
0.0333333333333333, 0.983333333333333, 0.783333333333333, 0.833333333333333,
0.65, 0.55), FLOW = c(2570, 1330, 1500, 3810, 4100, 1400, 10900,
5590, 5520, 6460, 1240, 2960, 11100, 33400, 13100, 4710, 2730,
9640, 1200, 3330, 4130, 24500, 9650, 2260, 13900, 6980, 38800,
8300, 17700, 49600, 4170, 22200, 47700, 3310, 15900, 1020, 13500,
25200, 2240, 135, 12500, 4650, 2580, 2300, 9680, 1660, 34600,
4010, 11800, 3070, 675, 14600, 2400, 406, 64300, 15100, 19800,
10900, 8040)), class = "data.frame", row.names = c(NA, -59L))
where bwpeaks$PROB is the weibull plotting position for the vector bwpeaks$FLOW. The ploting routine looks like:
library(ggplot2)
library(scales)
library(lmomco)
log10_minor_break = function (...){
function(x) {
minx = floor(min(log10(x), na.rm=T))-1;
maxx = ceiling(max(log10(x), na.rm=T))+1;
n_major = maxx-minx+1;
major_breaks = seq(minx, maxx, by=1)
minor_breaks =
rep(log10(seq(1, 9, by=1)), times = n_major)+
rep(major_breaks, each = 9)
return(10^(minor_breaks))
}
}
xbreaks <- c(0.002,0.01,0.10,0.25,0.5,0.8,0.9,0.95,0.975,0.99,0.995, 0.998)
log.range <- log10(range(bwpeaks$FLOW, na.rm = TRUE))
lower <- 10^floor(log.range[1])
upper <- 10^ceiling(log.range[2])
cap <- 100
ybreaks <- NULL
while(cap < upper) {
ybreaks <- c(ybreaks, seq(cap, cap*1, by = cap))
cap <- cap * 10
}
ggplot(bwpeaks) +
geom_point(aes(x=PROB, y=FLOW)) +
theme_bw() +
scale_y_continuous(trans="log10",
breaks=round(ybreaks, digits=2),
minor_breaks=log10_minor_break(),
name="Discharge (cfs)", labels=comma) +
scale_x_continuous(trans=probability_trans(distribution="norm"),
breaks=xbreaks,
labels=signif(prob2T(xbreaks), digits=3),
name="Return period (yrs)")
I am confused by scale_x_continuous(trans=probability_trans(distribution="norm"). Is there a way to calculate the transformed x variable bwpeaks$PROB without using ggplot?