我用下一个代码在 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)
.但这并没有给我饼图旁边的图例。
我必须使用哪个代码在中间的饼图旁边制作图例?
最佳答案
你可以玩x
和 y
来自 legend
的争论(参见 ?legend
):
legend(.9, .1, c("DH","UT","AM"), cex = 0.7, fill = colors)
但是,饼图可能不是表示数据的最佳方式,因为我们的眼睛不太擅长评估角度。饼图对我来说似乎合理的唯一用例是比较 2 个类别,因为由于 watch ,我们可以很容易地评估这些比例。
关于r - 如何在 R 中的饼图旁边制作图例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37206472/