Ggplot2 label: Combination of Greek symbol and exponential term,

I need to mark my y axis so that it first displays the word "Power", followed by the expression in square brackets: [micro Volt squared].

Microwave Voltage Power

I can create separate parts of the common label that I want, but I have problems when I want to combine them:

x <- 1:10; y <- 10:1; z <- data.frame(x,y)
g <- ggplot(z, aes(x,y) + geom_bar(stat='identity')

g + ylab('Power') # No problem
g + ylab(paste('Power [', ']')) #No problem
g + ylab(expression(mu)) # No problem
g + ylab(expression(V^2)) # No problem

However, this seems impossible:

g + ylab(paste('Power [', expression(mu), expression(V^2), ']'))

The output does not check the expressions (mu and V ^ 2):

ggplot2 Exit: y label problem

Where am I mistaken? Is the paste () command the wrong approach at all? I also looked at Unicode characters ( Unicode Characters in ggplot2 PDF Output ) ... but that would still leave me with the question of how to adequately combine all condition singles.

Your help is much appreciated!

+4
2

. , - . .

g + ylab(expression("Power"~"["*mu*V^2*"]"))
+4

, expression :

g + ylab(expression(paste("Power [",mu, V^2,"]")))
+2

Source: https://habr.com/ru/post/1624649/


All Articles