Hi!
Does anyone know how to make an x-axis like the one in the figure in ggplot? It is a cumulative distribution function (I think it is called Hazen probability)
Hi!
Does anyone know how to make an x-axis like the one in the figure in ggplot? It is a cumulative distribution function (I think it is called Hazen probability)
Here's an example of the log scaling for some arbitrary data, not a CDF
library(ggplot2)
set.seed(42)
d <- data.frame(x = rnorm(100), y = 1:100)
ggplot(d, aes(x = x, y = y)) +
geom_point() +
geom_smooth(se = FALSE) +
scale_x_log10() +
annotation_logticks(sides = "b") +
labs(title = "Example plot with log10 scale on x-axis") +
theme_minimal()
#> Warning in self$trans$transform(x): NaNs produced
#> Warning: Transformation introduced infinite values in continuous x-axis
#> Warning in self$trans$transform(x): NaNs produced
#> Warning: Transformation introduced infinite values in continuous x-axis
#> `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
#> Warning: Removed 46 rows containing non-finite values (`stat_smooth()`).
#> Warning: Removed 46 rows containing missing values (`geom_point()`).
Created on 2023-07-20 with reprex v2.0.2
Thank you so much for your input! But it's not what I'm looking for. The x-axis is not a log scale but a probability scale.
50 is the middle point , and as long as you go further to the left and right, the scale increases (i.e. the space is small between 50 and 60 or 40, but it is large between 99.5 and 99.9, same for 0.1 and 0.5)
There is a transformation probability_trans
in scales
library, that does exactly what you need.
library(tidyverse)
library(scales)
# Generate example data
n <- 100
df <- tibble(
x = seq(0, 1, length.out = n),
y = rnorm(n) |> sort()
)
# Create breaks for x-axis
b <- c(0.1, 0.5, 1, 2, 5, 10, 20, 30, 40, 40)
brks <- c(b, 50, 100 - rev(b)) / 100
# Plot with transformed x-axis
ggplot(df, aes(x = x, y = y)) +
geom_point() +
scale_x_continuous(trans = probability_trans("norm"), breaks = brks)
This is perfect! Thank you!
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.