r - 如何修复饼图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 写的一篇关于“为甜点省心”的文章
推荐阅读
- excel - Excel 和时间字段比较
- sql - Microsoft Access:错误消息行大小太大
- jsxgraph - 在一组对象中,Segment 不移动
- c++ - 为什么这个并发代码比另一个(都是 C++)慢?
- r - 合并标准 Eurobarometer 的多个数据集
- c# - 如何将数组中的元素与在c#中按顺序输入到文本框中的元素进行比较?
- angular - 添加评论时,基本组件的角度依赖注入失败
- python - 如何通过存储在不同 .json 文件中的键来分隔 .json 文件?
- javascript - 函数读取给定节点的所有属性的问题
- html - Angular 11 在 HTML 中填充输入