涉及希腊符号的方面标签 [英] Facet labels involving a greek symbol

查看:173
本文介绍了涉及希腊符号的方面标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有如下数据和图:

  mydata = data.frame(x = rnorm(4), y = runif(4),tau = c(0,0,1,1))
ggplot(mydata)+ geom_point(aes(x = x,y = y))+ facet_wrap(〜tau)

我希望facet标签分别读取tau = 0和tau = 1,头格式化为其希腊符号。我知道从另一个问题,使用贴标签 label_parsed 会自行格式化字母tau,但等号似乎会使事情复杂化。一个理想的解决方案不会要求我改变数据(即使头成为一个因子并命名它的级别),但我会采取任何行动:)解决方案 / div>

这里有一个解决方案,它包含 facet_grid 和adn按照其级别对tau进行索引。

  mydata = data.frame(x = rnorm(4),y = runif(4),tau = c(0,0,1,1))
ggplot(mydata)+ geom_point aes(x = x,y = y))+
facet_grid(〜tau,labeller = label_bquote(tau ^。(x)))



编辑获得tau = 0和tau = 1

  facet_grid(〜tau,labeller = label_bquote(tau ==。(x)))

Edit2 第二个变量sigma



通过定义一个自定义标签,我找到了这个解决方案。希望有人(ggplot2家伙)给我一个更简单的解决方案。



  my.label_bquote<  -  function(expr1 =(tau ==。(x)) (expr2)=(sigma ==。(x)))
{
quoted1< ){
value < - as.character(value)
if(variable =='tau')
lapply(value,function(x)
eval(substitute(bquote) (expr1,list(x = x)),list(expr1 = quoted1))))
else
lapply(value,function(x)
eval(substitute(bquote(expr2,list (x = x)),list(expr2 = quoted2))))
}
}

mydata = data.frame(x = rnorm(4),y = runif (4),tau = c(0,0,1,1),sigma = c(2,2,3,3))
ggplot(mydata)+ geom_point(aes(x = x,y = y ))+
facet_grid(sigma〜tau,labeller = my.label_bquote())


Suppose I have the data and plot as follows:

mydata = data.frame(x=rnorm(4), y=runif(4), tau=c(0,0,1,1))
ggplot(mydata) + geom_point(aes(x=x, y=y)) + facet_wrap(~ tau)

I would like the facet labels to read "tau=0" and "tau=1", respectively, with tau formatted as its greek symbol. I know from another question that using the labeller label_parsed will format the letter tau by itself, but the equal sign seems to complicate things. An ideal solution would not require me to change the data (i.e. make tau a factor and name its levels), but I will take whatever works :)

解决方案

here a solution with facet_grid adn indexing the tau by its levels.

mydata = data.frame(x=rnorm(4), y=runif(4), tau=c(0,0,1,1))
ggplot(mydata) + geom_point(aes(x=x, y=y)) +
         facet_grid(~ tau,labeller = label_bquote(tau ^ .(x)))

Edit To get the "tau=0" and "tau=1"

facet_grid(~ tau,labeller = label_bquote(tau == .(x)))

Edit2 second variable sigma

I find this solution, by defining a custom labeller. Hope someone ( ggplot2 guys ) give me a simpler solution.

my.label_bquote <- function (expr1 = (tau == .(x)),expr2 = (sigma == .(x))) 
{
   quoted1<- substitute(expr1)
   quoted2 <- substitute(expr2)
   function(variable, value) {
      value <- as.character(value)
      if(variable == 'tau')
         lapply(value, function(x)
               eval(substitute(bquote(expr1, list(x = x)),list(expr1 = quoted1))))
      else
         lapply(value, function(x) 
               eval(substitute(bquote(expr2, list(x = x)),list(expr2 = quoted2))))
   }
}

mydata = data.frame(x=rnorm(4), y=runif(4), tau=c(0,0,1,1),sigma=c(2,2,3,3))
ggplot(mydata) + geom_point(aes(x=x, y=y)) +
  facet_grid(sigma ~ tau,labeller = my.label_bquote())

这篇关于涉及希腊符号的方面标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆