我需要將情節中的單個分類 y 軸值更改為希臘字符,但我無法弄清楚。
library(tidyverse)
df = data.frame(y = c('a', 'b', 'c', 'd'),
xmin = rep(-2, 4),
x = rep(0, 4),
xmax = rep(2, 4))
df %>% ggplot(aes(y = y, x = x, xmin = xmin, xmax = xmax))
geom_pointrange(show.legend = F)
我想將 'd' 軸刻度標簽繪制為 δ 15 D 并保持其他 3 y 值不變。
我嘗試使用expression
這樣的方法將“d”更改為希臘語腳本
names <- df %>% pull(y)%>% recode( "d" = 'expression(delta^15~D)' )
df %>% ggplot(aes(y = y, x = x, xmin = xmin, xmax = xmax))
geom_pointrange(show.legend = F)
scale_y_discrete(labels = names)
但這只是列印單詞'expression(delta ^ 15?D)'
這也不起作用
names <- df %>% pull(y)%>% recode( "d" = paste0('expression(delta^15~D)') )
df %>% ggplot(aes(y = y, x = x, xmin = xmin, xmax = xmax))
geom_pointrange(show.legend = F)
scale_y_discrete(labels = names)
uj5u.com熱心網友回復:
您可以expression
在scale_y_discrete
. 從那里,expression
只為“d”指定。
library(ggplot2)
df = data.frame(y = c('a', 'b', 'c', 'd'),
xmin = rep(-2, 4),
x = rep(0, 4),
xmax = rep(2, 4))
ggplot(df, aes(y = y, x = x, xmin = xmin, xmax = xmax))
geom_pointrange(show.legend = F)
scale_y_discrete(labels = c("d" = expression(delta^15~D)))
由reprex 包(v2.0.1)于 2022-06-04 創建
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/485869.html