- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想用 facet_wrap 绘制一个 ggplot,它不显示实际的表格百分比,而是每组中给定答案的百分比。我必须这样做,因为我想表明,对于每个组来说,哪个答案最受选择和最重要。组的大小不一样。
示例数据:
group <- c(rep(c("Group1"), times = 10),rep(c("Group2"), times = 6),rep(c("Group3"), times = 4))
choice <- c(rep(c("a","b","c"),length.out = 10), "a","a","a","a","b","c","b","b","b","c")
df <- data.frame(cbind(group,choice))
prop.t
就好了,但是
prop.c
在我的图中显示,因为显示很重要,例如,第 2 组的 66.67% 更喜欢选择 a。
library(gmodels)
CrossTable(choice, group, prop.chisq=FALSE, prop.t = TRUE, prop.c = TRUE, prop.r = FALSE, format = "SPSS")
library(ggplot2)
g <- ggplot(df, aes_string(x="group", fill="group")) +
geom_bar(aes(y = (..count..)/sum(..count..)))+
ylab("percent")
g + facet_wrap(~ choice)
最佳答案
事先计算百分比可能更好:
library(dplyr)
dfl <- df %>%
group_by(group,choice) %>%
summarise(n=n()) %>%
group_by(group) %>%
mutate(perc=100*n/sum(n))
ggplot(dfl, aes(x=group, y=perc, fill=group)) +
geom_bar(stat="identity") +
ylab("percent") +
facet_wrap(~ choice)
ggplot(dfl, aes(x=choice, y=perc, fill=choice)) +
geom_bar(stat="identity") +
ylab("percent") +
facet_wrap(~ group)
关于r - 如何使用 facet_wrap 绘制 ggplot2,显示每个组的百分比,而不是整体百分比?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30233590/
我正在阅读Head First Design Patterns一书,在第382页上说: Composite Patterns is used when you have collection of o
我将我的电脑用作 wifi 热点,并将其他设备连接到它。然后使用wireshark,我可以看到特定设备上发送/接收的数据包,但是我怎样才能看到设备正在查看的完整网页而不是单独的数据包? 最佳答案 尝试
在 URL 中打开我的 Jenkins 时,我似乎无法登录它会抛出消息“用户缺少整体/读取权限”。我试过answer来自类似的问题,但禁用安全性不起作用。 Jenkins 继续抛出错误。有人建议我一起
我已经使用工具分配测试了我的应用程序并得到了这张图片: 如图所示,我的应用程序正常工作,但它通常以总字节数计值吗?我担心“#Allocations (Net/Overall)”,因为它的颜色是红色。这
我遵循教程 Deployment on Tomcat without modification of monitored webapps (beta) .监控站点正在运行,我可以看到统计页面。问题是
所以我有一个 div,其中整个东西都是一个 anchor 标记,我试图控制颜色在悬停时的显示方式并获得不同的结果。希望我能用 CSS 做到这一点。发生的事情是悬停,一个文本发生变化,但另一个没有。但是
我创建了一个程序,您可以在其中输入行驶的英里数和每 jar 油使用的加仑数,该程序会显示每 jar 油的 mpg。我使用的是 Visual Studio 2010。当我输入标记值 -1 时,系统会给出
我有一个由 N 个节点组成的 zookeeper 集群(彼此了解)。如果我在 zk 客户端连接字符串中只传递 M < N 个节点地址怎么办?集群的行为是什么? 在更具体的情况下,如果我只从集群中传递
我一直在试图弄清楚当使用诸如 pushViewController:animated、presentModalViewController:animated 和 UITabBarViewControl
我已经在 VIM 中安装了 minikube,并且我拥有具有所有权限的服务帐户 token 。是否有来自 kubernetes 的 API 来获取资源使用情况(总体)。 最佳答案 要获取 CPU 和内
如何通过 HTTP 客户端(例如 CURL、Insomnia、Postman 等)快速使用使用 JWT token 的 JHipster 生成的应用程序? 最佳答案 嗯,我研究了一段时间,发现你必须遵
我是一名优秀的程序员,十分优秀!