Closed karlropkins closed 3 years ago
It would help if you could post the output you get (e.g., by running your code through the reprex package). From what I see, the rendering is correct, but the r
and the -
clash somewhat. This may be font related. A different font might look better. One thing you could try is use a proper minus sign −
or an en-dash –
.
require(ggplot2)
#> Loading required package: ggplot2
require(ggtext)
#> Loading required package: ggtext
d <- data.frame(a = 1:10, b=1:10)
ggplot(d) +
geom_point(aes(a, b)) +
xlab("some text<br>NO<sub>2</sub> [μg.m<sup>-3</sup>.yr<sup>-1</sup>]") +
theme(axis.title.x = element_markdown())
ggplot(d) +
geom_point(aes(a, b)) +
xlab("some text<br>NO<sub>2</sub> [μg.m<sup>−3</sup>.yr<sup>−1</sup>]") +
theme(axis.title.x = element_markdown())
Created on 2020-08-21 by the reprex package (v0.3.0)
(sorry replex new to me but attached is what I get)
Interesting. The reprex work fine using my original code. Did some further checking and it is just when I run code directly in Rstudio. Fine in R console and using reprex. Appreciate any suggestion, but now assuming it is something to do with my rstudio, I'll update so if that fixes it. Thanks for your help/time
require(ggplot2)
#> Loading required package: ggplot2
require(ggtext)
#> Loading required package: ggtext
d <- data.frame(a = 1:10, b=1:10)
ggplot(d) +
geom_point(aes(a, b)) +
xlab("some text<br>NO<sub>2</sub> [μg.m<sup>-3</sup>.yr<sup>-1</sup>]") +
theme(axis.title.x = element_markdown())
Created on 2020-08-21 by the reprex package (v0.3.0)
The problem may be the specific graphics device you're using (which you may not even be aware of).
To have complete control over the graphics device, you can do something like this:
p <- ggplot(d) +
geom_point(aes(a, b)) +
xlab("some text<br>NO<sub>2</sub> [μg.m<sup>-3</sup>.yr<sup>-1</sup>]") +
theme(axis.title.x = element_markdown())
pdf("test.pdf") # pdf() graphics device
print(p)
dev.off()
In case of doubt, the ragg graphics devices tend to work the best, but they only produce bitmap output.
Hi, First quick note: Love the package; usually saves me loads of time. Not sure if this is issue or something I am missing... When I run below it adds extra space before superscripted -3 and maybe squashes yr and superscripted -1 together too much. Any fix or workaround for this?