簡體   English   中英

如何在R中的餅圖旁邊制作圖例?

[英]How can I make legend next to my piechart in R?

我在R中用下一個代碼制作了一個餅圖:

#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("centreright", c("DH","UT","AM"), cex=0.7, fill=colors) 但這並沒有給我一個旁邊我的餅圖的傳奇。

我必須使用哪些代碼在中間的餅圖旁邊制作一個圖例?

您可以使用legendxy參數(cf ?legend ):

legend(.9, .1, c("DH","UT","AM"), cex = 0.7, fill = colors)

但是,餅圖可能不是表示數據的最佳方式,因為我們的眼睛在評估角度方面不是很好。 餅圖對我來說似乎合理的唯一用例是比較兩個類別,因為由於手表,我們可以相當容易地評估這些比例。

在此輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM