【发布时间】:2021-03-10 02:16:56
【问题描述】:
我正在尝试想象工作是否按计划执行。
但是,我找不到好的包,所以我决定改用 ggplot 的段。
但是,我找不到编辑 yaxis 详细标签的方法,所以我有几个问题。
No1.
我通过安排工作时间和完成时间来制作图表。
我已将 0.1 添加到 yaxis 以将它们移动,但它会创建一个不需要的轴标签。
有什么办法可以去掉标签 1.1,2.1,3.1,...?
No2.
我想使用 work_name 列而不是 1,2,3,....
有没有办法做到这一点?
No3.
我想将 xaxis 更改为显示“M/D”或“YMD”而不是“M D”格式,
有没有办法做到这一点?
我有这个数据集。
> test$work_name
[1] "work-11" "work-12" "work-13" "work-14" "work-15"
> test$work_order_scedule
[1] 1 2 3 4 5
> test$scedule
[1] "2019-10-10 06:00:01 UTC" "2019-10-10 14:00:03 UTC" "2019-10-10 14:00:03 UTC"
[4] "2019-10-10 14:00:03 UTC" "2019-10-10 14:00:03 UTC"
> test$scedule_end
[1] "2019-10-10 14:00:02 UTC" "2019-10-10 22:00:00 UTC" "2019-10-10 22:00:00 UTC"
[4] "2019-10-10 22:00:00 UTC" "2019-10-10 22:00:00 UTC"
> test$do
[1] "2019-10-10 06:00:01 UTC" "2019-10-10 14:00:03 UTC" "2019-10-10 14:00:03 UTC"
[4] "2019-10-10 14:00:03 UTC" "2019-10-10 14:00:03 UTC"
> test$do_end
[1] "2019-10-11 20:50:08 UTC" "2019-10-11 20:49:57 UTC" "2019-10-11 20:49:54 UTC"
[4] "2019-10-11 20:49:52 UTC" "2019-10-11 20:49:50 UTC"
test<- data.frame(work_name=c("work-11","work-12","work-13","work-14","work-15"),
work_order_scedule=c(1 ,2 ,3 ,4 ,5),
scedule =c("2019-10-10 06:00:01" ,"2019-10-10 14:00:03", "2019-10-10 14:00:03","2019-10-10 14:00:03","2019-10-10 14:00:03"),
scedule_end=c("2019-10-10 14:00:02", "2019-10-10 22:00:00" ,"2019-10-10 22:00:00","2019-10-10 22:00:00" ,"2019-10-10 22:00:00"),
do=c("2019-10-10 06:00:01", "2019-10-10 14:00:03", "2019-10-10 14:00:03","2019-10-10 14:00:03" ,"2019-10-10 14:00:03"),
do_end=c("2019-10-11 20:50:08", "2019-10-11 20:49:57" ,"2019-10-11 20:49:54","2019-10-11 20:49:52" ,"2019-10-11 20:49:50")
)
和绘图代码
test %>%
ggplot() +
geom_segment(
aes(y=reorder(work_order_scedule,scedule), yend=reorder(work_order_scedule,scedule),
x=scedule, xend=scedule_end),
color="blue",
size=0.1)+
theme(axis.text.x = element_text(angle=90, hjust=1))+
geom_segment(
aes(y=reorder(work_order_scedule+0.1,scedule), yend=reorder(work_order_scedule+0.1,scedule),
x=do, xend=do_end),
color="black",
size=0.1)+
theme(axis.text.x = element_text(angle=90, hjust=1))
【问题讨论】:
-
我已经添加了数据。这是你的要求正确吗? (你能教我dput吗?我不知道)。谢谢你的评论!! @RonakShah
-
dput用于共享数据,所以您所做的也是正确的。您可以在控制台中运行dput(test)并通过编辑您的帖子将输出复制到此处。如果您有很多行,您可以通过dput(head(test, 10))选择前 10 行或前 15 行。 -
dput 真的很有用!谢谢你!我总是自己打字。我总是很累。