[英]how to fix legend in pie chart rstudio
pie(table(games_list$Genre),
main = "Rating Pie Chart",
col=brewer.pal(length(games_list$Genre),'Spectral'))
legend("topright",
legend=row.names(games_list$Genre),
fill = brewer.pal(length(games_list$Rating), 'Spectral'))
图例中的错误(“topright”,图例 = row.names(games_list$Genre),fill = brewer.pal(length(games_list$Rating),:“图例”的长度为 0
检查row.names(games_list$Genre)
是否返回了一些东西,并且是legend
参数所期望的。
因为您没有提供示例数据,所以我在下面的示例中使用了iris
数据集:
pie(table(iris$Species),
main = "Rating Pie Chart",
col=brewer.pal(
length(unique(iris$Species)), # we need only unique values
'Spectral'
)
)
legend("topright",
legend=unique(iris$Species),
fill = brewer.pal(
length(unique(iris$Species)),
'Spectral'
)
)
顺便说一句,如果您要显示超过 2 或 3 个类型/类,最好使用条形图。 这是 Stephen Few 写的一篇关于“为甜点省心”的文章
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.