Replies: 2 comments
-
|
Hi Neil, Thanks for your question. It's a little hard without your data or a reproducible example but I'll try to help. A few points:
Here is some code which you should hopefully be able to apply to your own data. library(ggplot2)
library(ggprism)
# non-log transformed x data means you need to use scale_x_log10()
# and pay attention to the limits and breaks
df <- data.frame(
x = 10^(seq(-10, -3, 1)),
y = 1:8
)
ggplot(df, aes(x = x, y = y)) +
geom_point() +
scale_x_log10(
limits = c(1e-10, 1e-3),
breaks = 10^(seq(-10, -3, 1)),
minor_breaks = rep(1:9, 7)*(10^rep(-10:-4, each = 9)),
guide = "prism_offset_minor"
)# log transformed x data means you need to use scale_x_continuous()
# limits and breaks are a little simpler here
df2 <- data.frame(
x = log10(10^(seq(-10, -3, 1))),
y = 1:8
)
ggplot(df2, aes(x = x, y = y)) +
geom_point() +
scale_x_continuous(
limits = c(-10, -3),
breaks = seq(-10, -3, 1),
minor_breaks = log10(rep(1:9, 7)*(10^rep(-10:-4, each = 9))),
guide = "prism_offset_minor"
)# I hope this code will help
ggplot(df2, aes(x = x, y = y)) +
geom_point() +
geom_smooth() +
theme_prism(base_size = 14) +
labs(x = "od", y = "concn") +
scale_x_continuous(
limits = c(-10, -3),
breaks = seq(-10, -3, 1),
minor_breaks = log10(rep(1:9, 7)*(10^rep(-10:-4, each = 9))),
guide = "prism_offset_minor",
labels = function(lab) {
do.call(
expression,
lapply(paste(lab), function(x) bquote(bold("10"^.(x))))
)
}
)
#> `geom_smooth()` using method = 'loess' and formula 'y ~ x'Created on 2022-01-17 by the reprex package (v2.0.1) |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Charlotte thanks for your help. I discovered part of the problem was
geom_smooth(nls or nlslm) does not work with log scales. I think that was
the problem. With my 95%CI's I used geom_line and ribbon. However I don't
understand this line of code or only partly
minor_breaks = log10(rep(1:9, 7)*(10^rep(-10:-4, each = 9)))
I've also been trying to make my code fairly generic so it determines
the x axis upper and lower limits and the major minor breaks are done
for you.
This attached file is my best attempt so far using ggprism. The data
could be better and is slightly with todays assay!
Thanks again for your help Neil
…On Mon, 17 Jan 2022 at 03:43, Charlotte Dawson ***@***.***> wrote:
Hi Neil,
Thanks for your question. It's a little hard without your data or a reproducible
example <https://reprex.tidyverse.org> but I'll try to help.
A few points:
- You shouldn't need to use annotation_logticks() if you are using guide
= "prism_offset_minor" and are setting up the minor ticks with a
function.
- The issue is likely with the axis scaling step and whether or not
your data has been log10 transformed.
Here is some code which you should hopefully be able to apply to your own
data.
library(ggplot2)
library(ggprism)
# non-log transformed x data means you need to use scale_x_log10()# and pay attention to the limits and breaksdf <- data.frame(
x = 10^(seq(-10, -3, 1)),
y = 1:8
)
ggplot(df, aes(x = x, y = y)) +
geom_point() +
scale_x_log10(
limits = c(1e-10, 1e-3),
breaks = 10^(seq(-10, -3, 1)),
minor_breaks = rep(1:9, 7)*(10^rep(-10:-4, each = 9)),
guide = "prism_offset_minor"
)
<https://camo.githubusercontent.com/687c894817da5eabe31072f9074f24f90c5c966c2504f641e941eaeca2dec0b9/68747470733a2f2f692e696d6775722e636f6d2f6a4a37384936522e706e67>
# log transformed x data means you need to use scale_x_continuous()# limits and breaks are a little simpler heredf2 <- data.frame(
x = log10(10^(seq(-10, -3, 1))),
y = 1:8
)
ggplot(df2, aes(x = x, y = y)) +
geom_point() +
scale_x_continuous(
limits = c(-10, -3),
breaks = seq(-10, -3, 1),
minor_breaks = log10(rep(1:9, 7)*(10^rep(-10:-4, each = 9))),
guide = "prism_offset_minor"
)
<https://camo.githubusercontent.com/c7aba7fba6e0c7f176075c4a147c8feb211172ff0b2744771a0a4d0d9da707d6/68747470733a2f2f692e696d6775722e636f6d2f57744c745750552e706e67>
# I hope this code will help
ggplot(df2, aes(x = x, y = y)) +
geom_point() +
geom_smooth() +
theme_prism(base_size = 14) +
labs(x = "od", y = "concn") +
scale_x_continuous(
limits = c(-10, -3),
breaks = seq(-10, -3, 1),
minor_breaks = log10(rep(1:9, 7)*(10^rep(-10:-4, each = 9))),
guide = "prism_offset_minor",
labels = function(lab) {
do.call(
expression,
lapply(paste(lab), function(x) bquote(bold("10"^.(x))))
)
}
)#> `geom_smooth()` using method = 'loess' and formula 'y ~ x'
<https://camo.githubusercontent.com/5744b5dccd789bd38c48c124bbe26b7f9dc011aaa1867b6ecda698ced16ce590/68747470733a2f2f692e696d6775722e636f6d2f59727534716a442e706e67>
Created on 2022-01-17 by the reprex package <https://reprex.tidyverse.org>
(v2.0.1)
—
Reply to this email directly, view it on GitHub
<#14 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AXFZ2N3NSM7CYCS7O6MXUWLUWOF5VANCNFSM5LMFVTHQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment



Uh oh!
There was an error while loading. Please reload this page.
-
Charlotte thanks for the library. I've tried to replicate the above but failed. I've tried with my actual x axis limits and generic code using the max an min x values. The attached image is almost all right for the x axis apart from the top and bottom bits which are funny but its stripped out my points and my regression and points. I do need the minor tick marks since I'm trying to work out the MDC and RDL from the 95CI.
My code is as as follows
``p <- ggplot(df, aes(x = x, y = y))
p <- p +geom_point()
p <- p + geom_smooth(method="nls",formula = fitmodel, se = FALSE,
method.args = list(start = list(a = a_start2, b =b_start2, c = c_start2, d = d_start2)))
p<- p + theme_prism(base_size = 14)
p<- p + ylab("od") +xlab("concn")
p<- p + annotation_logticks(side="b", outside = TRUE, size=1, mid = unit(0.1, "cm"), long = unit(0.2, "cm")) +
coord_cartesian(clip = "off")
p<- p + scale_x_continuous(
limits = c(min.size_x, max.size_x),
breaks = min.size_x:max.size_x,
guide = "prism_offset_minor",
minor_breaks = log10(rep(1:9, 7)*(10^rep(-4:4, each = 9))),
labels = function(lab) {
do.call(
expression,
lapply(paste(lab), function(x) bquote(bold("10"^.(x))))
)
}
)Please could you set me straight. Ta Neil
Beta Was this translation helpful? Give feedback.
All reactions