use*_*269 3 charts r legend pie-chart
我用以下代码在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)
Run Code Online (Sandbox Code Playgroud)
但我想在我的饼图旁边添加图例。我也曾尝试下面的代码:legend("centreright", c("DH","UT","AM"), cex=0.7, fill=colors)。但这在饼图旁边并没有给我一个传说。
在中间的饼形图旁边,我必须使用哪种代码制作图例?
您可以使用(cf )中的xand y参数:legend?legend
legend(.9, .1, c("DH","UT","AM"), cex = 0.7, fill = colors)
Run Code Online (Sandbox Code Playgroud)
但是,饼图可能并不是代表您数据的最佳方法,因为我们的眼睛在评估角度方面不是很好。对于我来说,饼状图合理的唯一用例是比较两个类别,因为由于手表的原因,我们可以很容易地评估这些比例。