如何在边距内移动/对齐R中的饼图

问题描述 投票:0回答:1

我在R中制作了一个饼图,但标签覆盖了该图。如何将图向左移动以查看完整图?

现在我的代码是

pie(slices_Pjob_rel, labels = lbls_Pjob_rel, cex = .6, main="Participant Household Job Holders", radius = 1,
    col = c("skyblue3","lightcyan1"))
legend("right", c("1: mother", "2: father", "3: sister", "4: brother", 
                     "5: aunt", "6: uncle", "7: other female relative", 
                     "8: other male relative"), cex = 0.8)

给我以下内容:1

谢谢

r plot label alignment pie-chart
1个回答
0
投票

您可以使用par来调整绘图的边距(分别包括底部,左侧,顶部和右侧边距。

您可以通过在x功能中提供ylegend值来设置图例的位置。

这是示例数据的结果:

# Make example slices and labels
slices <- c(5, 15, 8, 12, 10, 15, 30, 5)
slices_labels <- 1:8

# Adjust margins
par(mar=c(2,0,2,2))

# Draw pie chart
pie(slices, labels = slices_labels, cex = .6, main="Participant Household Job Holders", radius = 1,
    col = c("skyblue3","lightcyan1"))

# Add legend specifying x and y
legend(x = 1.2, y = .3, c("1: mother", "2: father", "3: sister", "4: brother", 
                  "5: aunt", "6: uncle", "7: other female relative", 
                  "8: other male relative"), cex = 0.8)

example plot with legend

© www.soinside.com 2019 - 2024. All rights reserved.