[英]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.