我怎样才能在我的PIECART中的PIECART旁边创建图例?

我怎样才能在我的PIECART中的PIECART旁边创建图例?,r,charts,legend,pie-chart,R,Charts,Legend,Pie Chart,我已在R中制作了一个piechart,其中包含以下代码: #make slices slices <- c(19, 26, 55) # Define some colors colors <- c("yellow2","olivedrab3","orangered3") # Calculate the percentage for each day, rounded to one decimal place slices_labels <- round(slices/su

我已在R中制作了一个piechart,其中包含以下代码:

#make slices
slices <- c(19, 26, 55)

# Define some colors 
colors <- c("yellow2","olivedrab3","orangered3")

# Calculate the percentage for each day, rounded to one decimal place
slices_labels <- round(slices/sum(slices) * 100, 1)

# Concatenate a '%' char after each value
slices_labels <- paste(slices_labels, "%", sep="")

# Create a pie chart with defined heading and custom colors and labels
pie(slices, main="Sum", col=colors, labels=slices_labels, cex=0.8)

# Create a legend at the right   
legend("topright", c("DH","UT","AM"), cex=0.7, fill=colors)
#制作切片

切片您可以使用
legend
(cf
?legend
)中的
x
y
参数:

然而,饼图可能不是表示数据的最佳方式,因为我们的眼睛在评估角度方面不是很好。在我看来,饼图唯一合理的用途是比较两个类别,因为根据手表,我们可以很容易地评估这些比例


lengend
无法识别
“centeright”
。有关详细信息,请参见图例。
图例(“右”、c(“DH”、“UT”、“AM”)、cex=0.7、填充=颜色)是否给出了所需的结果?谢谢您的回答。我已经有了答案;)A+1指出饼图不是可视化数据的最佳方式:-)(在帮助页面中也突出显示了这一点,请参见
?饼图
)感谢它的代码!我必须制作饼图来可视化数据。我认为在论文中设置饼图是很好的,这样其他人可以一眼就能理解你的数据。这是我的观点,我认为你不可能轻易理解饼图,因为判断角度不如判断位置那么容易。我认为这也是你用百分比标记切片的原因,因为否则很难判断比例。快速的谷歌搜索会为你提供大量反对使用馅饼的材料(例如)
legend(.9, .1, c("DH","UT","AM"), cex = 0.7, fill = colors)