r - 没有使用 Rmisc 和 ggplot 的图例
问题描述
我正在尝试为分类变量与分类变量创建 3 个图。我没有看到任何关于不同类别变量 C1、C4、C5 的图例。条形图也是灰色的。该数据集包含 9 个分类变量和 6 个数值变量的信息。C1、C4、C5分别有2、4、3个类别。已雇用 (1,0) 是显示候选人是否会被雇用的变量。
install.packages("Rmisc")
library(Rmisc)
p1<-ggplot(hireouti, aes(x = Hired, fill = C1)) + geom_bar(position = 'stack', show.legend=TRUE)
p2<-ggplot(hireouti, aes(x = Hired, fill = C4)) + geom_bar(position = 'stack', show.legend=TRUE)
p3<-ggplot(hireouti, aes(x = Hired, fill = C5)) + geom_bar(position = 'stack', show.legend=TRUE)
multiplot(p1,p2,p3, cols = 3)
下面的第一个可视化是我得到的输出。我想获得像下面第二个这样的可视化。
我已经能够用图例重现可视化。
我已经执行了下面的代码,C1、C4、C5 是数字。我试过转换成因子。
p1<-ggplot(hireouti, aes(x = Hired, fill = factor(C1))) + geom_bar(position = 'stack', show.legend = TRUE)
p2<-ggplot(hireouti, aes(x = Hired, fill = factor(C4))) + geom_bar(position = 'stack', show.legend = TRUE)
p3<-ggplot(hireouti, aes(x = Hired, fill = factor(C5))) + geom_bar(position = 'stack', show.legend = TRUE)
multiplot(p1,p2,p3, cols = 3)
解决方案
推荐阅读
- android - Android分析器如何减少本机内存使用
- android - 一加设备面临连接超时问题
- flutter - Flutter http包中服务器响应的长度
- triggers - Salesforce 代码覆盖失败:尽管 Sandbox 中的代码覆盖率为 100%,但无法在生产中部署 Apex 触发器
- java - 如何创建具有命名卷的容器?
- vue.js - 使用 Rest API POST 将文件上传到 Google Cloud Buckets
- php - WooCommerce:在完成一定数量的订单或一个订单的最小数量后自动更改用户角色
- c - 在文件读/写操作返回 -1 后调用 fsync
- python - Python 中 lambda 函数的多个文件和一个处理程序
- mysql - 通过在 MySQL 中组合两个表来获取每个数据的计数