- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想知道(如果可能的话)如何在 中绘制这样的图R .
例如,30 人(x 轴),工作近 300-400 小时(y 轴),每个人在 6 项特定事件中分配的时间以颜色显示。
示例数据:
| People | Act 1 | Act 2 | Act 3 | Act 4 | Act 5 | Act 6 |
|Person 1| 18 | 20 | 32 | 75 | 64 | 18 |
|Person 1| 40 | 25 | 02 | 04 | 17 | 20 |
|Person 2| 58 | 45 | 32 | 75 | 64 | 18 |
|Person 3| 10 | 15 | 11 | 28 | 15 | 92 |
|Person 1| 11 | 11 | 02 | 05 | 04 | 08 |
plot(table(data$worker),col=unique(data$worker))
最佳答案
您需要一个堆积柱形图,它在 y 轴上显示每种事件类型的人均工作小时数的绝对值(总计)。
首先,像这样组织你的数据集:
person hours.worked activity
1 18 1
1 20 2
...
3 11 3
3 28 4
...
1 4 5
1 8 6
#reproducible example (same as OP's data)
df = structure(list(person = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L),
hours.worked = c(18L, 20L, 32L, 75L, 64L,18L, 40L, 25L, 2L, 4L, 17L, 20L, 58L, 45L, 32L, 75L, 64L, 18L, 10L, 15L, 11L, 28L, 15L, 92L, 11L, 11L, 2L, 5L, 4L, 8L),
activity = c(1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L)),
.Names = c("person", "hours.worked", "activity"),
class = "data.frame",
row.names = c(NA, -30L))
df$person = factor(df$person,levels=c(1,2,3)) #control person order in x axis (left to right)
df$activity = factor(df$activity,levels=c(6,5,4,3,2,1)) #control order of stacks within column (top to base)
library(ggplot2)
ggplot(data=df, aes(x=person,y=hours.worked,fill=activity)) +
geom_col(position="stack") +
scale_fill_manual(breaks = c(1,2,3,4,5,6), #control order of legend keys (top to bottom)
values = c("#F564E3","#619CFF","#00BFC4","#00BA38","#B79F00","#F8766D")) #control fill of legend keys and columns stacks (surprisingly, this will honor the order of factor levels instead of order of 'breaks')
关于r - R中的堆积柱状图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15456731/
我计划为游戏的标记(图钉)构建在线 map ,但我无法设置标记的正确纬度。 原始 map 是一个2048*2048px的正方形 然后我得到了标记(数千个) map 坐标用 0 到 100 之间的 x、
数据可视化在数据分析和呈现方面起着重要的作用,而Python作为一种强大的编程语言,提供了多种库和工具,可以轻松创建各种类型的图表。本文将为您提供Python画图代码大全,包含常用的折线图、柱状图、饼
统计图形种类繁多, 有柱状图, 折线图, 扇形图等等, 而统计图形的绘制方法也有很多, 有flash制作的统计图形, 有水晶报表生成统计图形, 有专门制图软件制作, 也有编程语言自己制作的;这里我们
jpgraph简介 jpgraph是开源的php统计图表生成库,基于php的gd2图形库构建,把生成统计图的相关操作封装,隐藏了部分复杂的操作,使在php页面上输出统计图表变得更加容易。jpgra
请参阅下面的图表。我正在以编程方式构建图表,所以请不要使用 asp.net 控制语法。 如何更改横条后面水平和垂直交叉的网格线颜色?如您所见,我已经找到了如何更改实际轴颜色的方法,但网格颜色仍为黑色。
我一直试图在图表的水平轴上显示所有标签,但我一直无法做到! 我尝试使用 hAxis.showTextEvery=1 但不起作用 (见 https://developers.google.com/cha
我是一名优秀的程序员,十分优秀!