I wish to create a geom_tile plot which summarises the output of a particular model I've been working with. Specifically, in each tile I want to display the beta coefficient with the p-value on a new line. However I would like to use an italicised 'p' i.e ., p = 0.05
below is what I am trying to achieve except I would like to use italicised 'p'
df = data.frame(x = letters[1:10],y = letters[11:20], value = c(1:10),p = c((1:10)/10))
ggplot(df, aes(x = x, y = y)) +
geom_tile() +
geom_text(mapping = aes(label = paste(value, "\n",'p', "=", p)), parse = F, color = "white")
However, when I set parse = T and use expression(), I run into problems
I've tried
ggplot(df, aes(x = x, y = y)) +
geom_tile() +
geom_text(mapping = aes(label = paste(value,"/n",expression(italic("p")), "==", p)), parse = T, color = "white")
This only outputs the 'value', not the'p = ..' on the new line
and if I try without usign the new line,
ggplot(df, aes(x = x, y = y)) +
geom_tile() +
geom_text(mapping = aes(label = paste(value,expression(italic("p")), "==", p)), parse = T, color = "white")
I get the following error:
Error in geom_text()
:
! Problem while converting geom to grob.
ℹ Error occurred in the 2nd layer.
Caused by error in parse()
:
! :1:3: unexpected symbol
1: 1 italic
^
Is there a workaround?