admin管理员组文章数量:1332890
I have some data I'm plotting like this:
g <- ggplot(datapile, aes(x = Re, y = CD))
g <- g + geom_line(data = datapile, linetype = "solid", size = 1)
g <- g + scale_y_continuous(trans='log10', limits = c(0.01, 400), n.breaks = 20)
g <- g + scale_x_continuous(trans='log10', limits = c(0.02, 1e7), n.breaks = 20)
g <- g + ylab(expression(Drag~Coefficient*","~C[D]))
g <- g + xlab(expression(Reynolds~Number*","~frac(rho~V~d, mu)))
g
It looks fine, but I'd like the numbers on the axis to appear like they do in this picture:
Anyone know this offhand?
I have some data I'm plotting like this:
g <- ggplot(datapile, aes(x = Re, y = CD))
g <- g + geom_line(data = datapile, linetype = "solid", size = 1)
g <- g + scale_y_continuous(trans='log10', limits = c(0.01, 400), n.breaks = 20)
g <- g + scale_x_continuous(trans='log10', limits = c(0.02, 1e7), n.breaks = 20)
g <- g + ylab(expression(Drag~Coefficient*","~C[D]))
g <- g + xlab(expression(Reynolds~Number*","~frac(rho~V~d, mu)))
g
It looks fine, but I'd like the numbers on the axis to appear like they do in this picture:
Anyone know this offhand?
Share Improve this question asked Nov 21, 2024 at 0:43 Karl WolfschtaggKarl Wolfschtagg 5672 silver badges16 bronze badges 1- You mean specifically the x-axis? (Seems tricky ...) – Ben Bolker Commented Nov 21, 2024 at 1:09
1 Answer
Reset to default 5library(ggplot2)
library(ggtext) # to specify superscript etc. using html
# using a trick from https://stackoverflow/a/23902261/6851825
# "outer binary product" multiplies all combinations of the two vectors,
# concatenate to get vector of breaks
brks <- c(c(1,2,4,6,8) %o% 10^(0:10))
brks_log <- log10(brks)
labs <- ifelse(brks_log == floor(brks_log),
paste0("<br>10<sup>", brks_log, "</sup>"),
paste(brks / 10^floor(brks_log)))
ggplot(mtcars, aes(wt^5, mpg^3)) +
geom_point() +
scale_x_log10(breaks = brks, minor_breaks = NULL,
labels = labs, guide = "axis_logticks") +
theme(axis.text.x = element_markdown())
本文标签: rggplot multiline loglog labelsStack Overflow
版权声明:本文标题:r - ggplot multi-line log-log labels - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742320443a2452676.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论