簡體   English   中英

在 R 中的條件 ifelse 上添加上標

[英]Adding upper subscript on conditional ifelse in R

我正在努力格式化Name列,以便在Value列大於 10 時添加上下標。有什么建議嗎? 這是一個示例數據集。

 tibble(Name = LETTERS[1:10], 
        Value = sample(5:15,10))

結果應該是這樣的: A^1當值大於 10

set.seed(123)
d <- tibble(Name = LETTERS[1:10], 
       Value = sample(5:15,10)) %>%
  mutate(Name = if_else(Value>10, paste0(Name, "^1"), Name))


library(ggplot2)
ggplot(d, aes(Name, Value)) + geom_bar(stat = "identity") +
 scale_x_discrete("Axis label", labels = parse(text = d$Name)) +
  theme(axis.text.x = element_text(vjust=0))

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM