如何使用ggtern增大三元图的轴标签及轴数值尺寸?
问题:增大三元图的轴标签与轴数值尺寸
我用以下R代码绘制三元图,想要增大图中三个轴的标签以及轴上数值刻度的尺寸:
数据集
| EE | ES | SE | id | |
|---|---|---|---|---|
| 1 | 0.15 | 0.25 | 0.60 | 1 |
| 2 | 0.30 | 0.20 | 0.50 | 1 |
| 3 | 0.15 | 0.15 | 0.70 | 1 |
| 4 | 0.40 | 0.20 | 0.40 | 1 |
| 5 | 0.70 | 0.10 | 0.20 | 1 |
| 6 | 0.50 | 0.30 | 0.20 | 1 |
| 7 | 0.32 | 0.20 | 0.48 | 2 |
原绘图代码
idNP <- "1"; idMObj <- "2"; Group <- as.factor(NP_Mobj$id) IWRM_Trinagle_NPCriteria_MObj <- ggtern(NP_Mobj, aes( x = SE, y = EE, z = ES )) + geom_point(aes(color = Group ), size = 8) + theme_showarrows() + labs(xarrow = "Social equity (SE)", yarrow = "Economic efficiency (EE)", zarrow = "Environmental sustainability (ES)") + scale_colour_manual(breaks = c(idNP, idMObj), values = c("black", "red")) + theme_clockwise() + theme_bw() IWRM_Trinagle_NPCriteria_MObj <- IWRM_Trinagle_NPCriteria_MObj + theme(legend.position="none")
修改方案
由于ggtern基于ggplot2,可以通过theme()函数中的参数直接调整轴标签和刻度的大小。以下是修改后的完整代码,已将轴标签翻译为中文,并增大了刻度与标签尺寸:
idNP <- "1"; idMObj <- "2"; Group <- as.factor(NP_Mobj$id) IWRM_Trinagle_NPCriteria_MObj <- ggtern(NP_Mobj, aes( x = SE, y = EE, z = ES )) + geom_point(aes(color = Group ), size = 8) + theme_showarrows() + labs(xarrow = "社会公平 (SE)", yarrow = "经济效率 (EE)", zarrow = "环境可持续性 (ES)") + scale_colour_manual(breaks = c(idNP, idMObj), values = c("black", "red")) + theme_clockwise() + theme_bw() + theme( # 设置轴上数值刻度的文字大小 axis.text = element_text(size = 12), # 设置轴标签的文字大小 axis.title = element_text(size = 14), legend.position = "none" ) # 输出图形 print(IWRM_Trinagle_NPCriteria_MObj)
参数说明
axis.text = element_text(size = 12):统一调整三个轴的数值刻度大小,可根据需求修改size数值;axis.title = element_text(size = 14):统一调整三个轴的标签大小,同样可自定义size;- 若需单独调整某一个轴的刻度或标签,可使用
axis.text.x/axis.text.y/axis.text.z以及axis.title.x/axis.title.y/axis.title.z进行精准设置。
内容的提问来源于stack exchange,提问作者ΚΩΝΣΤΑΝΤΙΝΟΣ ΠΑΝΑΓΙΩΤΟΥ
相关产品推荐
相关产品推荐

