- 更改x軸分類(lèi)標(biāo)簽的名稱(chēng)
scale_x_discrete(labels=c('A', 'B'))
- 更改x軸分類(lèi)標(biāo)簽的順序
#方法1畜侦,在x軸映射里面改因子數(shù)據(jù)的層次
factor(team, level=c('Mavs', 'Heat', 'Nets', 'Lakers')
#方法2,
scale_x_discrete(limit = c('a', 'd', 'c','b', 'f', 'e'))
ref:r - How do you specifically order ggplot2 x axis instead of alphabetical order? - Stack Overflow
- 更改facet分面標(biāo)簽文本及順序
facet_grid(~factor(team, levels=c('C', 'D', 'A', 'B'))旋膳,## 更改標(biāo)簽順序
labeller = as_labeller(c(A='new1', B='new2', C='new3', D='new4'))) ## 更改標(biāo)簽內(nèi)容
- 更改legend的標(biāo)簽文本及順序
### 更改圖例標(biāo)題文本
+ labs(fill = "xxxx")
###翻轉(zhuǎn)圖例順序
# Use guides function to reverse legend for
# a specific aesthetic (fill, linetype, shape or color)
p + guides(fill = guide_legend(reverse=TRUE))
# Or use scale_fill_discrete (same as above)
p + scale_fill_discrete(guide = guide_legend(reverse=TRUE))
### 自定義圖例子標(biāo)簽順序
# Change the order of legend items
p + scale_x_discrete(limits=c("B", "C", "A"))
### 更改圖例標(biāo)題和子標(biāo)簽文本
# Edit legend title and labels
p + scale_fill_discrete(name = "legend name", labels = c("A", "B", "C"))
## 或者
scale_fill_manual(
values = c("#7ecaa5", "#feb769"), ## 改顏色
name = NULL, ## 改名字
labels = c("Baseline\n(No-weighted)", "KE-weighted") ## 改子標(biāo)簽名字
)
- 更改y軸的位置溺忧,
scale_y_continuous(position = "right")
- 坐標(biāo)軸數(shù)值轉(zhuǎn)百分比
labels = scales::percent