Is it possible to get the partial derivative symbol via expression()
in ggplot2
, e.g. to be used in axis labels?
I am talking about this symbol, often also refered to as 'del' or 'curly d': https://en.wikipedia.org/wiki/%E2%88%82
It has unicode number U+2202, but when I try to include it in ggplot, it fails:
a <- b <- rnorm(100)
plot.df <- data.frame(a,b)
ggplot(plot.df,aes(a,b)) +
geom_point() +
xlab(expression('\u2202'))
For comparison, using e.g. the plus/minus sign with unicode number U+00B1 works fine:
ggplot(plot.df,aes(a,b)) +
geom_point() +
xlab(expression('\u00b1'))
With the ggtext
package you can use HTML entities:
library(ggplot2)
library(ggtext)
a <- b <- rnorm(100)
plot.df <- data.frame(a,b)
ggplot(plot.df, aes(a,b)) +
geom_point() +
xlab("∂") +
theme(axis.title.x = element_markdown(size = 20))
you can achieve this using the keyword partialdiff
. using your example:
ggplot(plot.df,aes(a,b)) +
geom_point() +
xlab(expression(paste(partialdiff,"y","/",partialdiff,"x")))
This link provides some good reference on the matter.
Depending how far you want to go. You can eventually use TikzDevice
library to save the plot directly as a tex.file. It might take longer to compile the graph but I find it more flexible.
library(tikzDevice)
tikz("/tmp/test.tex",standAlone = TRUE)
ggplot(plot.df,aes(a,b)) +
geom_point() +
xlab("$\\frac{\\partial{y}}{\\partial{x}}$")
dev.off()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With